From 530910da3bc65906a7926b991e13e102ee26297f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 28 Nov 2024 16:23:39 +0100 Subject: [PATCH 01/65] test (SMS/E2E): Batches --- .../test/java/com/sinch/sdk/e2e/Config.java | 3 + .../sdk/e2e/domains/sms/v0/BatchesSteps.java | 367 ++++++++++++++++++ .../sinch/sdk/e2e/domains/sms/v0/SmsIT.java | 16 + pom.xml | 1 + 4 files changed, 387 insertions(+) create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/BatchesSteps.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java diff --git a/client/src/test/java/com/sinch/sdk/e2e/Config.java b/client/src/test/java/com/sinch/sdk/e2e/Config.java index 4c3d940f2..ce26aac1d 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/Config.java +++ b/client/src/test/java/com/sinch/sdk/e2e/Config.java @@ -4,6 +4,7 @@ import com.sinch.sdk.models.Configuration; import com.sinch.sdk.models.ConversationContext; import com.sinch.sdk.models.ConversationRegion; +import com.sinch.sdk.models.SmsContext; import com.sinch.sdk.models.VoiceContext; public class Config { @@ -21,6 +22,7 @@ public class Config { public static final String VOICE_HOST_NAME = "http://localhost:3019"; public static final String VOICE_MANAGEMENT_HOST_NAME = "http://localhost:3020"; + public static final String SMS_HOST_NAME = "http://localhost:3017"; private final SinchClient client; private Config() { @@ -44,6 +46,7 @@ private Config() { .setVoiceApplicationMngmtUrl(VOICE_MANAGEMENT_HOST_NAME) .setVoiceUrl(VOICE_HOST_NAME) .build()) + .setSmsContext(SmsContext.builder().setSmsUrl(SMS_HOST_NAME).build()) .build(); client = new SinchClient(configuration); diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/BatchesSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/BatchesSteps.java new file mode 100644 index 000000000..ca7d7053b --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/BatchesSteps.java @@ -0,0 +1,367 @@ +package com.sinch.sdk.e2e.domains.sms.v0; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.utils.Pair; +import com.sinch.sdk.domains.sms.BatchesService; +import com.sinch.sdk.domains.sms.models.BatchText; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.DryRun; +import com.sinch.sdk.domains.sms.models.DryRunPerRecipientDetails; +import com.sinch.sdk.domains.sms.models.Parameters; +import com.sinch.sdk.domains.sms.models.requests.BatchesListRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; +import com.sinch.sdk.domains.sms.models.requests.UpdateSmsBatchTextRequest; +import com.sinch.sdk.domains.sms.models.responses.BatchesListResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class BatchesSteps { + + BatchesService service; + + BatchText sendTextResponse; + BatchText sendTextWithParametersResponse; + DryRun dryRunResponse; + BatchesListResponse listOnePageResponse; + BatchesListResponse listAllResponse; + BatchesListResponse listAllByPageResponse; + BatchText getBatchResponse; + BatchText updateResponse; + BatchText replaceResponse; + BatchText cancelResponse; + Boolean sendDeliveryFeedbackPassed; + + @Given("^the SMS service \"Batches\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().batches(); + } + + @When("^I send a request to send a text message$") + public void send() { + SendSmsBatchTextRequest request = + SendSmsBatchTextRequest.builder() + .setBody("SMS body message") + .setTo(Collections.singletonList("+12017777777")) + .setFrom("+12015555555") + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setFeedbackEnabled(true) + .build(); + + sendTextResponse = service.send(request); + } + + @When("^I send a request to send a text message with multiple parameters$") + public void sendWithParameters() { + SendSmsBatchTextRequest request = + SendSmsBatchTextRequest.builder() + .setBody("Hello ${name}! Get 20% off with this discount code ${code}") + .setTo(Arrays.asList("+12017777777", "+12018888888")) + .setFrom("+12015555555") + .setParameters( + new Parameters( + Arrays.asList( + new Parameters.Entry("name", new Pair<>("+12017777777", "John"), "there"), + new Parameters.Entry("name", new Pair<>("+12018888888", "Paul")), + new Parameters.Entry( + "code", new Pair<>("+12017777777", "HALLOWEEN20 \uD83C\uDF83"))))) + .setDeliveryReport(DeliveryReportType.FULL) + .build(); + + sendTextWithParametersResponse = service.send(request); + } + + @When("^I send a request to perform a dry run of a batch$") + public void dryRun() { + SendSmsBatchTextRequest request = + SendSmsBatchTextRequest.builder() + .setBody("Hello ${name}!") + .setTo(Arrays.asList("+12017777777", "+12018888888", "+12019999999")) + .setFrom("+12015555555") + .setParameters( + new Parameters( + Arrays.asList( + new Parameters.Entry("name", new Pair<>("+12017777777", "John"), "there")))) + .setDeliveryReport(DeliveryReportType.NONE) + .build(); + + dryRunResponse = service.dryRun(true, 3, request); + } + + @When("^I send a request to list the SMS batches$") + public void listOnePage() { + BatchesListRequestParameters request = + BatchesListRequestParameters.builder().setPageSize(2).build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the SMS batches$") + public void listAll() { + BatchesListRequestParameters request = + BatchesListRequestParameters.builder().setPageSize(2).build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the SMS batches pages$") + public void listAllByPage() { + BatchesListRequestParameters request = + BatchesListRequestParameters.builder().setPageSize(2).build(); + + listAllByPageResponse = service.list(request); + } + + @When("^I send a request to retrieve an SMS batch$") + public void get() { + + getBatchResponse = service.get("foo"); + } + + @When("^I send a request to update an SMS batch$") + public void update() { + + UpdateSmsBatchTextRequest request = + UpdateSmsBatchTextRequest.builder() + .setFrom("+12016666666") + .setToAdd(Collections.singletonList("01W4FFL35P4NC4K35SMSGROUP1")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .build(); + updateResponse = service.update("foo", request); + } + + @When("^I send a request to replace an SMS batch$") + public void replace() { + + SendSmsBatchTextRequest request = + SendSmsBatchTextRequest.builder() + .setFrom("+12016666666") + .setTo(Collections.singletonList("+12018888888")) + .setBody("This is the replacement batch") + .setSendAt(Instant.parse("2024-06-06T09:35:00Z")) + .build(); + replaceResponse = service.replace("foo", request); + } + + @When("^I send a request to cancel an SMS batch$") + public void cancel() { + + cancelResponse = service.cancel("foo"); + } + + @When("^I send a request to send delivery feedbacks$") + public void sendDeliveryFeedback() { + + service.sendDeliveryFeedback("foo", Arrays.asList("+12017777777")); + sendDeliveryFeedbackPassed = true; + } + + @Then("the response contains the text SMS details") + public void sendResult() { + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Collections.singletonList("12017777777")) + .setFrom("12015555555") + .setCanceled(false) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(sendTextResponse, expected); + } + + @Then("the response contains the text SMS details with multiple parameters") + public void sendWithParametersResult() { + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH2") + .setTo(Arrays.asList("12017777777", "12018888888")) + .setFrom("12015555555") + .setCanceled(false) + .setParameters( + new Parameters( + Arrays.asList( + new Parameters.Entry("name", new Pair<>("+12017777777", "John"), "there"), + new Parameters.Entry("name", new Pair<>("+12018888888", "Paul")), + new Parameters.Entry( + "code", new Pair<>("+12017777777", "HALLOWEEN20 \uD83C\uDF83"))))) + .setBody("Hello ${name}! Get 20% off with this discount code ${code}") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setExpireAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(sendTextWithParametersResponse, expected); + } + + @Then( + "the response contains the calculated bodies and number of parts for all messages in the" + + " batch") + public void dryRunResult() { + DryRun expected = + DryRun.builder() + .setNumberOfRecipients(3) + .setNumberOfMessages(3) + .setPerRecipient( + Arrays.asList( + DryRunPerRecipientDetails.builder() + .setRecipient("12017777777") + .setNumberOfParts(1) + .setBody("Hello John!") + .setEncoding("text") + .build(), + DryRunPerRecipientDetails.builder() + .setRecipient("12019999999") + .setNumberOfParts(1) + .setBody("Hello there!") + .setEncoding("text") + .build(), + DryRunPerRecipientDetails.builder() + .setRecipient("12018888888") + .setNumberOfParts(1) + .setBody("Hello there!") + .setEncoding("text") + .build())) + .build(); + + TestHelpers.recursiveEquals(dryRunResponse, expected); + } + + @Then("the response contains \"{int}\" SMS batches") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the SMS batches list contains \"{int}\" SMS batches") + public void listAllResult(int expected) { + + BatchesListResponse response = + null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the SMS batches iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } + + @Then("the response contains the SMS batch details") + public void getResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Collections.singletonList("12017777777")) + .setFrom("12015555555") + .setCanceled(false) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(getBatchResponse, expected); + } + + @Then("the response contains the SMS batch details with updated data") + public void updateResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Arrays.asList("12017777777", "01W4FFL35P4NC4K35SMSGROUP1")) + .setFrom("12016666666") + .setCanceled(false) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:48.054Z")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(updateResponse, expected); + } + + @Then("the response contains the new SMS batch details with the provided data for replacement") + public void replaceResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Arrays.asList("12018888888")) + .setFrom("12016666666") + .setCanceled(false) + .setBody("This is the replacement batch") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:23:32.504Z")) + .setDeliveryReport(DeliveryReportType.NONE) + .setSendAt(Instant.parse("2024-06-06T09:35:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:35:00Z")) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(replaceResponse, expected); + } + + @Then("the response contains the SMS batch details with a cancelled status") + public void cancelResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Arrays.asList("12017777777")) + .setFrom("12015555555") + .setCanceled(true) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:29.978Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(cancelResponse, expected); + } + + @Then("the delivery feedback response contains no data") + public void setSendDeliveryFeedbackResult() { + Assertions.assertTrue(sendDeliveryFeedbackPassed); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java new file mode 100644 index 000000000..fdacedbb4 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java @@ -0,0 +1,16 @@ +package com.sinch.sdk.e2e.domains.sms.v0; + +import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; + +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectClasspathResource; +import org.junit.platform.suite.api.Suite; +import org.junit.platform.suite.api.SuiteDisplayName; + +@Suite +@SuiteDisplayName("SMS V0") +@IncludeEngines("cucumber") +@SelectClasspathResource("features/sms/batches.feature") +@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v0") +public class SmsIT {} diff --git a/pom.xml b/pom.xml index f7a9ee392..bb8469c9b 100644 --- a/pom.xml +++ b/pom.xml @@ -322,6 +322,7 @@ com.sinch.sdk.e2e.domains.conversation.ConversationIT + com.sinch.sdk.e2e.domains.sms.v0.SmsIT com.sinch.sdk.e2e.domains.voice.v0.VoiceIT com.sinch.sdk.e2e.domains.voice.v1.VoiceIT From 2764467a4b12b8d085bf008ecc0a9319136b4295 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 28 Nov 2024 17:45:10 +0100 Subject: [PATCH 02/65] test (SMS/E2E): Delivery reports --- .../domains/sms/v0/DeliveryReportsSteps.java | 184 ++++++++++++++++++ .../sinch/sdk/e2e/domains/sms/v0/SmsIT.java | 1 + 2 files changed, 185 insertions(+) create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/DeliveryReportsSteps.java diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/DeliveryReportsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/DeliveryReportsSteps.java new file mode 100644 index 000000000..74ec37136 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/DeliveryReportsSteps.java @@ -0,0 +1,184 @@ +package com.sinch.sdk.e2e.domains.sms.v0; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatch; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatusDetails; +import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportBatchGetRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.DeliveryReportListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.DeliveryReportsListResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class DeliveryReportsSteps { + + DeliveryReportsService service; + + DeliveryReportBatch summaryReport; + DeliveryReportBatch fullReport; + DeliveryReportRecipient recipientReport; + DeliveryReportsListResponse listOnePageResponse; + DeliveryReportsListResponse listAllResponse; + DeliveryReportsListResponse listAllByPageResponse; + + @Given("^the SMS service \"Delivery Reports\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().deliveryReports(); + } + + @When("^I send a request to retrieve a summary SMS delivery report$") + public void getSummary() { + DeliveryReportBatchGetRequestParameters request = + DeliveryReportBatchGetRequestParameters.builder() + .setType(DeliveryReportType.SUMMARY) + .setStatuses(Arrays.asList(DeliveryReportStatus.DELIVERED, DeliveryReportStatus.FAILED)) + .setCodes(Arrays.asList(15, 0)) + .build(); + + summaryReport = service.get("foo", request); + } + + @When("^I send a request to retrieve a full SMS delivery report$") + public void getFull() { + DeliveryReportBatchGetRequestParameters request = + DeliveryReportBatchGetRequestParameters.builder().setType(DeliveryReportType.FULL).build(); + + fullReport = service.get("foo", request); + } + + @When("^I send a request to retrieve a recipient's delivery report$") + public void getRecipient() { + + recipientReport = service.getForNumber("foo", "+12345678"); + } + + @When("^I send a request to list the SMS delivery reports$") + public void listOnePage() { + DeliveryReportListRequestParameters request = + DeliveryReportListRequestParameters.builder().setPageSize(2).build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the SMS delivery reports$") + public void listAll() { + DeliveryReportListRequestParameters request = + DeliveryReportListRequestParameters.builder().setPageSize(2).build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the SMS delivery reports pages$") + public void listAllByPage() { + DeliveryReportListRequestParameters request = + DeliveryReportListRequestParameters.builder().setPageSize(2).build(); + + listAllByPageResponse = service.list(request); + } + + @Then("the response contains a summary SMS delivery report") + public void getSummaryResult() { + DeliveryReportBatch expected = + DeliveryReportBatchSMS.builder() + .setBatchId("01W4FFL35P4NC4K35SMSBATCH1") + .setClientReference("reference_e2e") + .setStatuses( + Arrays.asList( + DeliveryReportStatusDetails.builder() + .setCode(15) + .setCount(1) + .setStatus(DeliveryReportStatus.FAILED) + .build(), + DeliveryReportStatusDetails.builder() + .setCode(0) + .setCount(1) + .setStatus(DeliveryReportStatus.DELIVERED) + .build())) + .setTotalMessageCount(2) + .build(); + TestHelpers.recursiveEquals(summaryReport, expected); + } + + @Then("the response contains a full SMS delivery report") + public void getFullResult() { + DeliveryReportBatch expected = + DeliveryReportBatchSMS.builder() + .setBatchId("01W4FFL35P4NC4K35SMSBATCH1") + .setClientReference("reference_e2e") + .setStatuses( + Arrays.asList( + DeliveryReportStatusDetails.builder() + .setCode(0) + .setCount(1) + .setStatus(DeliveryReportStatus.DELIVERED) + .setRecipients(Collections.singletonList("12017777777")) + .build(), + DeliveryReportStatusDetails.builder() + .setCode(15) + .setCount(1) + .setStatus(DeliveryReportStatus.FAILED) + .setRecipients(Collections.singletonList("12018888888")) + .build())) + .setTotalMessageCount(2) + .build(); + TestHelpers.recursiveEquals(fullReport, expected); + } + + @Then("the response contains the recipient's delivery report details") + public void getRecipientResult() { + DeliveryReportRecipient expected = + DeliveryReportRecipientSMS.builder() + .setAt(Instant.parse("2024-06-06T13:06:27.833Z")) + .setBatchId("01W4FFL35P4NC4K35SMSBATCH1") + .setClientReference("reference_e2e") + .setCode(DeliveryReportErrorCode.from(0)) + .setOperatorStatusAt(Instant.parse("2024-06-06T13:06:00Z")) + .setRecipient("12017777777") + .setStatus(DeliveryReportStatus.DELIVERED) + .build(); + + TestHelpers.recursiveEquals(recipientReport, expected); + } + + @Then("the response contains \"{int}\" SMS delivery reports") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the SMS delivery reports list contains \"{int}\" SMS delivery reports") + public void listAllResult(int expected) { + DeliveryReportsListResponse response = + null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the SMS delivery reports iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java index fdacedbb4..6e40261e8 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java @@ -12,5 +12,6 @@ @SuiteDisplayName("SMS V0") @IncludeEngines("cucumber") @SelectClasspathResource("features/sms/batches.feature") +@SelectClasspathResource("features/sms/delivery-reports.feature") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v0") public class SmsIT {} From 92eddfee263753ecf0633764de445fa0710b2f14 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 29 Nov 2024 08:00:14 +0100 Subject: [PATCH 03/65] test (SMS/E2E): Groups --- .../sdk/e2e/domains/sms/v0/GroupsSteps.java | 227 ++++++++++++++++++ .../sinch/sdk/e2e/domains/sms/v0/SmsIT.java | 1 + 2 files changed, 228 insertions(+) create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/GroupsSteps.java diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/GroupsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/GroupsSteps.java new file mode 100644 index 000000000..41edc12d1 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/GroupsSteps.java @@ -0,0 +1,227 @@ +package com.sinch.sdk.e2e.domains.sms.v0; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.GroupsService; +import com.sinch.sdk.domains.sms.models.Group; +import com.sinch.sdk.domains.sms.models.requests.GroupCreateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupReplaceRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupUpdateRequestParameters; +import com.sinch.sdk.domains.sms.models.requests.GroupsListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.GroupsListResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class GroupsSteps { + + GroupsService service; + Group createResponse; + Group getResponse; + GroupsListResponse listOnePageResponse; + GroupsListResponse listAllResponse; + GroupsListResponse listAllByPageResponse; + Group updateResponse; + Group updateRemoveNameResponse; + Group replaceResponse; + Boolean deletePassed; + Collection lisMembersResponse; + + @Given("^the SMS service \"Groups\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().groups(); + } + + @When("^I send a request to create an SMS group$") + public void create() { + GroupCreateRequestParameters request = + GroupCreateRequestParameters.builder() + .setName("Group master") + .setMembers(Arrays.asList("+12017778888", "+12018887777")) + .setChildGroupIds(Collections.singletonList("01W4FFL35P4NC4K35SUBGROUP1")) + .build(); + + createResponse = service.create(request); + } + + @When("^I send a request to retrieve an SMS group$") + public void get() { + + getResponse = service.get("01W4FFL35P4NC4K35SMSGROUP1"); + } + + @When("^I send a request to list the existing SMS groups$") + public void listOnePage() { + GroupsListRequestParameters request = + GroupsListRequestParameters.builder().setPageSize(2).build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the SMS groups$") + public void listAll() { + GroupsListRequestParameters request = + GroupsListRequestParameters.builder().setPageSize(2).build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the SMS groups pages$") + public void listAllByPage() { + GroupsListRequestParameters request = + GroupsListRequestParameters.builder().setPageSize(2).build(); + + listAllByPageResponse = service.list(request); + } + + @When("^I send a request to update an SMS group$") + public void update() { + + GroupUpdateRequestParameters parameters = + GroupUpdateRequestParameters.builder() + .setName("Updated group name") + .setAdd(Arrays.asList("+12017771111", "+12017772222")) + .setRemove(Arrays.asList("+12017773333", "+12017774444")) + .setAddFromGroup("01W4FFL35P4NC4K35SMSGROUP2") + .setRemoveFromGroup("01W4FFL35P4NC4K35SMSGROUP3") + .build(); + updateResponse = service.update("groupid", parameters); + } + + @When("^I send a request to update an SMS group to remove its name$") + public void updateRemoveName() { + + GroupUpdateRequestParameters parameters = + GroupUpdateRequestParameters.builder().setName(null).build(); + updateRemoveNameResponse = service.update("groupid", parameters); + } + + @When("^I send a request to replace an SMS group$") + public void replace() { + + GroupReplaceRequestParameters parameters = + GroupReplaceRequestParameters.builder() + .setName("Replacement group") + .setMembers(Arrays.asList("+12018881111", "+12018882222", "+12018883333")) + .build(); + replaceResponse = service.replace("groupid", parameters); + } + + @When("^I send a request to delete an SMS group$") + public void delete() { + + service.delete("groupid"); + deletePassed = true; + } + + @When("^I send a request to list the members of an SMS group$") + public void listMembers() { + + lisMembersResponse = service.listMembers("groupid"); + } + + @Then("the response contains the SMS group details") + public void createOrGetResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP1") + .setName("Group master") + .setSize(2) + .setCreatedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setModifiedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setChildGroupIds(Collections.singletonList("01W4FFL35P4NC4K35SUBGROUP1")) + .build(); + + Group current = null != createResponse ? createResponse : getResponse; + + TestHelpers.recursiveEquals(current, expected); + } + + @Then("the response contains \"{int}\" SMS groups") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the SMS groups list contains \"{int}\" SMS groups") + public void listAllResult(int expected) { + GroupsListResponse response = null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the SMS groups iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } + + @Then("the response contains the updated SMS group details") + public void updateResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP1") + .setName("Updated group name") + .setSize(6) + .setCreatedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:19:58.147Z")) + .setChildGroupIds(Arrays.asList("01W4FFL35P4NC4K35SUBGROUP1")) + .build(); + TestHelpers.recursiveEquals(updateResponse, expected); + } + + @Then("the response contains the updated SMS group details where the name has been removed") + public void updateRemoveNameResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP2") + .setSize(5) + .setCreatedAt(Instant.parse("2024-06-06T12:45:18.761Z")) + .setModifiedAt(Instant.parse("2024-06-06T13:12:05.137Z")) + .setChildGroupIds(Collections.emptyList()) + .build(); + TestHelpers.recursiveEquals(updateRemoveNameResponse, expected); + } + + @Then("the response contains the replaced SMS group details") + public void replaceResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP1") + .setName("Replacement group") + .setSize(3) + .setCreatedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setModifiedAt(Instant.parse("2024-08-21T09:39:36.679Z")) + .setChildGroupIds(Collections.singletonList("01W4FFL35P4NC4K35SUBGROUP1")) + .build(); + TestHelpers.recursiveEquals(replaceResponse, expected); + } + + @Then("the delete SMS group response contains no data") + public void deleteResult() { + Assertions.assertTrue(deletePassed); + } + + @Then("the response contains the phone numbers of the SMS group") + public void lisMembersResult() { + Collection expected = + new ArrayList<>(Arrays.asList("12018881111", "12018882222", "12018883333")); + TestHelpers.recursiveEquals(lisMembersResponse, expected); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java index 6e40261e8..0c23d4228 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java @@ -13,5 +13,6 @@ @IncludeEngines("cucumber") @SelectClasspathResource("features/sms/batches.feature") @SelectClasspathResource("features/sms/delivery-reports.feature") +@SelectClasspathResource("features/sms/groups.feature") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v0") public class SmsIT {} From 79ae5a96a2d89b42c6edb5957b95fb33ff4d6316 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 29 Nov 2024 08:18:16 +0100 Subject: [PATCH 04/65] test (SMS/E2E): Inbounds --- .../sdk/e2e/domains/sms/v0/InboundsSteps.java | 112 ++++++++++++++++++ .../sinch/sdk/e2e/domains/sms/v0/SmsIT.java | 1 + 2 files changed, 113 insertions(+) create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/InboundsSteps.java diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/InboundsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/InboundsSteps.java new file mode 100644 index 000000000..85f323bbe --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/InboundsSteps.java @@ -0,0 +1,112 @@ +package com.sinch.sdk.e2e.domains.sms.v0; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.InboundsService; +import com.sinch.sdk.domains.sms.models.InboundText; +import com.sinch.sdk.domains.sms.models.requests.InboundsListRequestParameters; +import com.sinch.sdk.domains.sms.models.responses.InboundsListResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class InboundsSteps { + + InboundsService service; + InboundText getResponse; + InboundsListResponse listOnePageResponse; + InboundsListResponse listAllResponse; + InboundsListResponse listAllByPageResponse; + + @Given("^the SMS service \"Inbounds\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().inbounds(); + } + + @When("^I send a request to retrieve an inbound message") + public void get() { + + getResponse = (InboundText) service.get("inboundid"); + } + + @When("^I send a request to list the inbound messages$") + public void listOnePage() { + InboundsListRequestParameters request = + InboundsListRequestParameters.builder() + .setTo(Arrays.asList("12017777777", "12018888888")) + .setPageSize(2) + .build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the inbound messages$") + public void listAll() { + InboundsListRequestParameters request = + InboundsListRequestParameters.builder() + .setTo(Arrays.asList("12017777777", "12018888888")) + .setPageSize(2) + .build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the inbound messages pages$") + public void listAllByPage() { + InboundsListRequestParameters request = + InboundsListRequestParameters.builder() + .setTo(Arrays.asList("12017777777", "12018888888")) + .setPageSize(2) + .build(); + + listAllByPageResponse = service.list(request); + } + + @Then("the response contains the inbound message details") + public void getResult() { + InboundText expected = + InboundText.builder() + .setBody("Hello John!") + .setFrom("12015555555") + .setId("01W4FFL35P4NC4K35INBOUND01") + .setOperatorId("311071") + .setReceivedAt(Instant.parse("2024-06-06T14:16:54.777Z")) + .setTo("12017777777") + .build(); + + TestHelpers.recursiveEquals(getResponse, expected); + } + + @Then("the response contains \"{int}\" inbound messages") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the inbound messages list contains \"{int}\" inbound messages") + public void listAllResult(int expected) { + InboundsListResponse response = + null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the inbound messages iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java index 0c23d4228..f0a703bf6 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java @@ -14,5 +14,6 @@ @SelectClasspathResource("features/sms/batches.feature") @SelectClasspathResource("features/sms/delivery-reports.feature") @SelectClasspathResource("features/sms/groups.feature") +@SelectClasspathResource("features/sms/inbounds.feature") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v0") public class SmsIT {} From 14d13abda6f33cb981134ec852eff908e67feeb9 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 29 Nov 2024 09:31:50 +0100 Subject: [PATCH 05/65] test (SMS/E2E): Webhooks --- .../sinch/sdk/e2e/domains/sms/v0/SmsIT.java | 5 +- .../sdk/e2e/domains/sms/v0/WebhooksSteps.java | 141 ++++++++++++++++++ 2 files changed, 142 insertions(+), 4 deletions(-) create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java index f0a703bf6..0361145fe 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/SmsIT.java @@ -11,9 +11,6 @@ @Suite @SuiteDisplayName("SMS V0") @IncludeEngines("cucumber") -@SelectClasspathResource("features/sms/batches.feature") -@SelectClasspathResource("features/sms/delivery-reports.feature") -@SelectClasspathResource("features/sms/groups.feature") -@SelectClasspathResource("features/sms/inbounds.feature") +@SelectClasspathResource("features/sms") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v0") public class SmsIT {} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java new file mode 100644 index 000000000..13b860ab5 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java @@ -0,0 +1,141 @@ +package com.sinch.sdk.e2e.domains.sms.v0; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.WebHooksService; +import com.sinch.sdk.domains.sms.models.DeliveryReportBatchSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportErrorCode; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipient; +import com.sinch.sdk.domains.sms.models.DeliveryReportRecipientSMS; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatus; +import com.sinch.sdk.domains.sms.models.DeliveryReportStatusDetails; +import com.sinch.sdk.domains.sms.models.InboundText; +import com.sinch.sdk.domains.sms.models.webhooks.WebhooksEvent; +import com.sinch.sdk.e2e.Config; +import com.sinch.sdk.e2e.domains.WebhooksHelper; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.io.IOException; +import java.net.URL; +import java.time.Instant; +import java.util.Arrays; + +public class WebhooksSteps { + + static final String WEBHOOKS_PATH_PREFIX = "/webhooks/sms"; + static final String WEBHOOKS_URL = Config.SMS_HOST_NAME + WEBHOOKS_PATH_PREFIX; + + WebHooksService service; + WebhooksHelper.Response incoming; + WebhooksHelper.Response deliveryReport; + WebhooksHelper.Response deliveryReportRecipientDelivered; + WebhooksHelper.Response deliveryReportRecipientAborted; + + @Given("^the SMS Webhooks handler is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().webHooks(); + } + + @When("^I send a request to trigger an \"incoming SMS\" event") + public void incoming() throws IOException { + + incoming = WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/incoming-sms"), service::parse); + } + + @When("^I send a request to trigger an \"SMS delivery report\" event") + public void deliveryReport() throws IOException { + + deliveryReport = + WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/delivery-report-sms"), service::parse); + } + + @When( + "^I send a request to trigger an \"SMS recipient delivery report\" event with the status" + + " \"Delivered\"") + public void deliveryReportRecipientDelivered() throws IOException { + + deliveryReportRecipientDelivered = + WebhooksHelper.callURL( + new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-delivered"), service::parse); + } + + @When( + "^I send a request to trigger an \"SMS recipient delivery report\" event with the status" + + " \"Aborted\"") + public void deliveryReportRecipientAborted() throws IOException { + + deliveryReportRecipientAborted = + WebhooksHelper.callURL( + new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-aborted"), service::parse); + } + + @Then("the SMS event describes an \"incoming SMS\" event") + public void incomingResult() { + InboundText expected = + InboundText.builder() + .setBody("Hello John! 👋") + .setFrom("12015555555") + .setId("01W4FFL35P4NC4K35SMSBATCH8") + .setOperatorId("311071") + .setReceivedAt(Instant.parse("2024-06-06T07:52:37.386Z")) + .setTo("12017777777") + .build(); + + TestHelpers.recursiveEquals(incoming.event, expected); + } + + @Then("the SMS event describes an \"SMS delivery report\" event") + public void deliveryReportResult() { + DeliveryReportBatchSMS expected = + DeliveryReportBatchSMS.builder() + .setBatchId("01W4FFL35P4NC4K35SMSBATCH8") + .setClientReference("client-ref") + .setStatuses( + Arrays.asList( + DeliveryReportStatusDetails.builder() + .setCode(0) + .setCount(2) + .setRecipients(Arrays.asList("12017777777", "33612345678")) + .setStatus(DeliveryReportStatus.DELIVERED) + .build())) + .setTotalMessageCount(2) + .build(); + + TestHelpers.recursiveEquals(deliveryReport.event, expected); + } + + @Then( + "the SMS event describes an SMS recipient delivery report event with the status" + + " \"Delivered\"") + public void deliveryReportRecipientDeliveredResult() { + DeliveryReportRecipient expected = + DeliveryReportRecipientSMS.builder() + .setAt(Instant.parse("2024-06-06T08:17:19.210Z")) + .setBatchId("01W4FFL35P4NC4K35SMSBATCH9") + .setClientReference("client-ref") + .setCode(DeliveryReportErrorCode.from(0)) + .setOperatorStatusAt(Instant.parse("2024-06-06T08:17:00Z")) + .setRecipient("12017777777") + .setStatus(DeliveryReportStatus.DELIVERED) + .build(); + + TestHelpers.recursiveEquals(deliveryReportRecipientDelivered.event, expected); + } + + @Then( + "the SMS event describes an SMS recipient delivery report event with the status \"Aborted\"") + public void deliveryReportRecipientAbortedResult() { + DeliveryReportRecipient expected = + DeliveryReportRecipientSMS.builder() + .setAt(Instant.parse("2024-06-06T08:17:15.603Z")) + .setBatchId("01W4FFL35P4NC4K35SMSBATCH9") + .setClientReference("client-ref") + .setCode(DeliveryReportErrorCode.UNPROVISIONED_REGION) + .setRecipient("12010000000") + .setStatus(DeliveryReportStatus.ABORTED) + .build(); + + TestHelpers.recursiveEquals(deliveryReportRecipientAborted.event, expected); + } +} From 569dcbd7da56403654011813fe12ac735192c047 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 7 Dec 2024 09:57:22 +0100 Subject: [PATCH 06/65] feat (SMS): Define SMS v1 --- .../com/sinch/sdk/domains/sms/SMSService.java | 10 +++ .../sdk/domains/sms/adapters/SMSService.java | 13 +++ .../sdk/domains/sms/api/v1/SMSService.java | 5 ++ .../sms/api/v1/adapters/SMSService.java | 80 +++++++++++++++++++ .../sms/adapters/BatchesServiceTest.java | 6 +- .../converters/BatchDtoConverterTest.java | 12 +-- .../java/com/sinch/sdk/core/TestHelpers.java | 8 +- .../models/dto/v1/BinaryResponseDtoTest.java | 4 +- .../models/dto/v1/MediaResponseDtoTest.java | 4 +- .../models/dto/v1/SendSMSRequestDtoTest.java | 6 +- .../models/dto/v1/SendSMSResponseDtoTest.java | 6 +- .../models/dto/v1/TextResponseDtoTest.java | 4 +- .../request/BinaryRequestDto.json} | 0 .../request/MediaRequestDto.json} | 0 .../request/TextRequestDto.json} | 0 .../response/BatchBinaryDto.json} | 0 .../response/BatchMediaDto.json} | 0 .../response/BatchTextDto.json} | 0 .../com/sinch/sample/sms/batches/Send.java | 12 ++- 19 files changed, 144 insertions(+), 26 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java rename openapi-contracts/src/test/resources/domains/sms/v1/{SendSMSBinaryRequestDto.json => batches/request/BinaryRequestDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{SendSMSMediaRequestDto.json => batches/request/MediaRequestDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{SendSMSTextRequestDto.json => batches/request/TextRequestDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{BinaryResponseDto.json => batches/response/BatchBinaryDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{MediaResponseDto.json => batches/response/BatchMediaDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{TextResponseDto.json => batches/response/BatchTextDto.json} (100%) diff --git a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java index 1d0da811f..ca09e175c 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java @@ -9,6 +9,16 @@ */ public interface SMSService { + /** + * SMS Service V1 + * + * @return V1 service instance for project + * @see Documentation + * @since + */ + com.sinch.sdk.domains.sms.api.v1.SMSService v1(); + /** * Batches Service instance * diff --git a/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java index 11f8f8926..07ed46fd1 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/adapters/SMSService.java @@ -29,6 +29,7 @@ public class SMSService implements com.sinch.sdk.domains.sms.SMSService { private final String uriUUID; private final SmsContext context; private final HttpClient httpClient; + private com.sinch.sdk.domains.sms.api.v1.SMSService v1; private BatchesService batches; private WebHooksService webHooks; private DeliveryReportsService deliveryReports; @@ -60,6 +61,10 @@ public SMSService( this.authManagers = Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, oAuthManager)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + this.v1 = + new com.sinch.sdk.domains.sms.api.v1.adapters.SMSService( + credentials, context, oAuthServer, httpClient); } public SMSService( @@ -83,6 +88,14 @@ public SMSService( this.authManagers = Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, authManager)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + this.v1 = + new com.sinch.sdk.domains.sms.api.v1.adapters.SMSService(credentials, context, httpClient); + } + + @Override + public com.sinch.sdk.domains.sms.api.v1.SMSService v1() { + return this.v1; } @Override diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java new file mode 100644 index 000000000..702386a6f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -0,0 +1,5 @@ +package com.sinch.sdk.domains.sms.api.v1; + +public interface SMSService { + +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java new file mode 100644 index 000000000..c14d6dc7a --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -0,0 +1,80 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.sinch.sdk.auth.adapters.BearerAuthManager; +import com.sinch.sdk.auth.adapters.OAuthManager; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.utils.StringUtil; +import com.sinch.sdk.models.SmsContext; +import com.sinch.sdk.models.SmsServicePlanCredentials; +import com.sinch.sdk.models.UnifiedCredentials; +import java.util.AbstractMap; +import java.util.Map; +import java.util.Objects; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SMSService implements com.sinch.sdk.domains.sms.api.v1.SMSService { + + private static final Logger LOGGER = Logger.getLogger(SMSService.class.getName()); + + private static final String SECURITY_SCHEME_KEYWORD_SMS = "BearerAuth"; + private final String uriUUID; + private final SmsContext context; + private final HttpClient httpClient; + private BatchesService batches; + private final Map authManagers; + + public SMSService( + UnifiedCredentials credentials, + SmsContext context, + ServerConfiguration oAuthServer, + HttpClient httpClient) { + + Objects.requireNonNull(credentials, "Credentials must be defined"); + Objects.requireNonNull(context, "Context must be defined"); + StringUtil.requireNonEmpty(credentials.getKeyId(), "'keyId' must be defined"); + StringUtil.requireNonEmpty(credentials.getKeySecret(), "'keySecret' must be defined"); + StringUtil.requireNonEmpty(credentials.getProjectId(), "'projectId' must be defined"); + StringUtil.requireNonEmpty(context.getSmsUrl(), "'smsUrl' must be defined"); + + LOGGER.fine("Activate SMS API with server='" + context.getSmsServer().getUrl() + "'"); + + OAuthManager oAuthManager = + new OAuthManager(credentials, oAuthServer, new HttpMapper(), httpClient); + + this.uriUUID = credentials.getProjectId(); + this.context = context; + this.httpClient = httpClient; + this.authManagers = + Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, oAuthManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + public SMSService( + SmsServicePlanCredentials credentials, SmsContext context, HttpClient httpClient) { + + Objects.requireNonNull(credentials, "Credentials must be defined"); + Objects.requireNonNull(context, "Context must be defined"); + StringUtil.requireNonEmpty(credentials.getServicePlanId(), "'servicePlanId' must be defined"); + StringUtil.requireNonEmpty(credentials.getApiToken(), "'apiToken' must be defined"); + + LOGGER.fine( + "Activate SMS API with service plan ID support and server='" + + context.getSmsServer().getUrl() + + "'"); + + BearerAuthManager authManager = new BearerAuthManager(credentials.getApiToken()); + + this.uriUUID = credentials.getServicePlanId(); + this.context = context; + this.httpClient = httpClient; + this.authManagers = + Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_SMS, authManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index c1f461e02..bbc1be71d 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -246,13 +246,13 @@ public class BatchesServiceTest extends BaseTest { .setUdh(udh) .build(); - @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") public SendSMS201ResponseDto binaryResponseDto; - @GivenJsonResource("/domains/sms/v1/MediaResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") SendSMS201ResponseDto mediaResponseDto; - @GivenJsonResource("/domains/sms/v1/TextResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") SendSMS201ResponseDto textResponseDto; @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java index b5428ace0..7c9e2473d 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java @@ -27,22 +27,22 @@ @TestWithResources class BatchDtoConverterTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") public SendSMS201ResponseDto binaryResponseDto; - @GivenJsonResource("/domains/sms/v1/TextResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") public SendSMS201ResponseDto textResponseDto; - @GivenJsonResource("/domains/sms/v1/MediaResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") public SendSMS201ResponseDto mediaResponseDto; - @GivenJsonResource("/domains/sms/v1/SendSMSBinaryRequestDto.json") + @GivenJsonResource("/domains/sms/v1/batches/request/BinaryRequestDto.json") public SendSMSRequestDto sendBinaryRequestDto; - @GivenJsonResource("/domains/sms/v1/SendSMSTextRequestDto.json") + @GivenJsonResource("/domains/sms/v1/batches/request/TextRequestDto.json") public SendSMSRequestDto sendTextRequestDto; - @GivenJsonResource("/domains/sms/v1/SendSMSMediaRequestDto.json") + @GivenJsonResource("/domains/sms/v1/batches/request/MediaRequestDto.json") public SendSMSRequestDto sendMediaRequestDto; @GivenJsonResource("/domains/sms/v1/UpdateSMSTextRequestDto.json") diff --git a/core/src/test/java/com/sinch/sdk/core/TestHelpers.java b/core/src/test/java/com/sinch/sdk/core/TestHelpers.java index 0b965fe0b..e74f7db49 100644 --- a/core/src/test/java/com/sinch/sdk/core/TestHelpers.java +++ b/core/src/test/java/com/sinch/sdk/core/TestHelpers.java @@ -8,11 +8,11 @@ public class TestHelpers { private static final RecursiveComparisonConfiguration recursiveComparisonConfiguration = RecursiveComparisonConfiguration.builder().withStrictTypeChecking(true).build(); - public static void recursiveEquals(Object o1, Object o2) { + public static void recursiveEquals(Object actual, Object expected) { - Assertions.assertThat(o1.getClass()).isEqualTo(o2.getClass()); - Assertions.assertThat(o1) + Assertions.assertThat(actual.getClass()).isEqualTo(expected.getClass()); + Assertions.assertThat(actual) .usingRecursiveComparison(recursiveComparisonConfiguration) - .isEqualTo(o2); + .isEqualTo(expected); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java index b5d08594f..9e67b5e67 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources class BinaryResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") BinaryResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/BinaryResponseDto.json") + @GivenTextResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") String jsonStringDto; BinaryResponseDto dto = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java index 83af2afdd..4880cfcf1 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java @@ -19,10 +19,10 @@ @TestWithResources class MediaResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/MediaResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") MediaResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/MediaResponseDto.json") + @GivenTextResource("/domains/sms/v1/batches/response/BatchMediaDto.json") String jsonStringDto; ParameterObjDto parameterObjDto = new ParameterObjDto(); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java index a1507cefa..3be96cf8c 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java @@ -16,13 +16,13 @@ @TestWithResources class SendSMSRequestDtoTest extends BaseTest { - @GivenTextResource("/domains/sms/v1/SendSMSBinaryRequestDto.json") + @GivenTextResource("/domains/sms/v1/batches/request/BinaryRequestDto.json") String jsonRequestBinaryDto; - @GivenTextResource("/domains/sms/v1/SendSMSTextRequestDto.json") + @GivenTextResource("/domains/sms/v1/batches/request/TextRequestDto.json") String jsonRequestTextDto; - @GivenTextResource("/domains/sms/v1/SendSMSMediaRequestDto.json") + @GivenTextResource("/domains/sms/v1/batches/request/MediaRequestDto.json") String jsonRequestMediaDto; @Test diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java index 63284a7df..28331ed1e 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java @@ -17,13 +17,13 @@ @TestWithResources class SendSMSResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/BinaryResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") SendSMS201ResponseDto loadedBinary; - @GivenJsonResource("/domains/sms/v1/TextResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") SendSMS201ResponseDto loadedText; - @GivenJsonResource("/domains/sms/v1/MediaResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") SendSMS201ResponseDto loadedMedia; ParameterObjDto parameterObjDto = new ParameterObjDto(); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java index 2f14db82f..91b2808b5 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java @@ -19,10 +19,10 @@ @TestWithResources class TextResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/TextResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") TextResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/TextResponseDto.json") + @GivenTextResource("/domains/sms/v1/batches/response/BatchTextDto.json") String jsonStringDto; ParameterObjDto parameterObjDto = new ParameterObjDto(); diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSBinaryRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/BinaryRequestDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/SendSMSBinaryRequestDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/request/BinaryRequestDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/MediaRequestDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/SendSMSMediaRequestDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/request/MediaRequestDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/TextRequestDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/SendSMSTextRequestDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/request/TextRequestDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/BinaryResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchBinaryDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/BinaryResponseDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchBinaryDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/MediaResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/MediaResponseDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/TextResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchTextDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/TextResponseDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchTextDto.json diff --git a/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java b/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java index d8f8aa072..a5d4d82f1 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/batches/Send.java @@ -1,10 +1,13 @@ package com.sinch.sample.sms.batches; import com.sinch.sample.BaseApplication; +import com.sinch.sdk.core.utils.Pair; import com.sinch.sdk.domains.sms.models.BatchText; import com.sinch.sdk.domains.sms.models.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.Parameters; import com.sinch.sdk.domains.sms.models.requests.SendSmsBatchTextRequest; import java.io.IOException; +import java.util.Arrays; import java.util.Collections; import java.util.logging.Logger; @@ -29,9 +32,16 @@ public void run() { SendSmsBatchTextRequest.Builder builder = SendSmsBatchTextRequest.builder() .setTo(Collections.singletonList(phoneNumber)) - .setBody("the body") + .setBody("the body ${code}") .setClientReference("a client reference") .setFrom("+33123456789") + .setParameters( + new Parameters( + Arrays.asList( + new Parameters.Entry("name", new Pair<>("+12017777777", "John"), "there"), + new Parameters.Entry("name", new Pair<>("+12018888888", "Paul")), + new Parameters.Entry( + "code", new Pair<>(phoneNumber, "HALLOWEEN20 \uD83C\uDF83"))))) .setDeliveryReport(DeliveryReportType.FULL); // Overload default dashboard webhooks URL if defined From fe713d415ea9df7e63467ef3171c762b01019cfa Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 7 Dec 2024 10:02:47 +0100 Subject: [PATCH 07/65] feat (SMS/Batches): Support 'send' operation --- .../domains/sms/api/v1/BatchesService.java | 11 ++ .../sdk/domains/sms/api/v1/SMSService.java | 1 + .../sms/api/v1/adapters/BatchesService.java | 34 ++++ .../sms/api/v1/adapters/SMSService.java | 7 + .../v1/batches/request/BatchRequest.java | 3 + .../sms/models/v1/batches/response/Batch.java | 7 + .../request/SendBatchRequestDtoTest.java | 146 ++++++++++++++++++ .../response/SendBatchResponseDtoTest.java | 130 ++++++++++++++++ .../com/sinch/sample/sms/v1/batches/Send.java | 68 ++++++++ 9 files changed, 407 insertions(+) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java new file mode 100644 index 000000000..beeb46f5b --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -0,0 +1,11 @@ +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; + +public interface BatchesService { + + Batch send(BatchRequest batch) throws ApiException; + +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java index 702386a6f..b9bfd936a 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -2,4 +2,5 @@ public interface SMSService { + BatchesService batches(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java new file mode 100644 index 000000000..c497e6210 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -0,0 +1,34 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; +import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.models.SmsContext; +import java.util.Map; + +public class BatchesService implements com.sinch.sdk.domains.sms.api.v1.BatchesService { + + private final BatchesApi api; + + public BatchesService( + String uriUUID, + SmsContext context, + HttpClient httpClient, + Map authManagers) { + this.api = + new BatchesApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); + } + + protected BatchesApi getApi() { + return this.api; + } + + public Batch send(BatchRequest batch) throws ApiException { + return getApi().send(batch); + } + +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index c14d6dc7a..69b58844e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -77,4 +77,11 @@ public SMSService( .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); } + @Override + public BatchesService batches() { + if (null == this.batches) { + this.batches = new BatchesService(uriUUID, context, httpClient, authManagers); + } + return this.batches; + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java new file mode 100644 index 000000000..15c37afe0 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java @@ -0,0 +1,3 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +public interface BatchRequest {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java new file mode 100644 index 000000000..71c101738 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java @@ -0,0 +1,7 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.BatchResponseInternalImpl; + +@JsonDeserialize(using = BatchResponseInternalImpl.Deserializer.class) +public interface Batch {} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java new file mode 100644 index 000000000..948deeb10 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java @@ -0,0 +1,146 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class SendBatchRequestDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/batches/request/BinaryRequestDto.json") + String jsonRequestBinaryDto; + + @GivenTextResource("/domains/sms/v1/batches/request/TextRequestDto.json") + String jsonRequestTextDto; + + @GivenTextResource("/domains/sms/v1/batches/request/MediaRequestDto.json") + String jsonRequestMediaDto; + + @Test + void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { + + BinaryRequest binaryRequestDTO = + BinaryRequest.builder() + .setTo(Arrays.asList("+15551231234", "+15551256344")) + .setBody("Hi ${name} ({an identifier}) ! How are you?") + .setUdh("foo udh") + .setFrom("+15551231234") + .setDeliveryReport(DeliveryReportType.NONE) + .setSendAt(Instant.parse("2019-08-24T14:19:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:21:22Z")) + .setCallbackUrl("callback url") + .setClientReference("myReference") + .setFeedbackEnabled(false) + .setFromTon(6) + .setFromNpi(18) + .build(); + + String serializedString = objectMapper.writeValueAsString(binaryRequestDTO); + + JSONAssert.assertEquals(jsonRequestBinaryDto, serializedString, true); + } + + @Test + void serializeTextRequestDto() throws JsonProcessingException, JSONException { + + Map anIdentifierParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), + new AbstractMap.SimpleEntry<>("default", "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + TextRequest textRequestDTO = + TextRequest.builder() + .setTo(Arrays.asList("+15551231234", "+15551256344")) + .setBody("Hi ${name} ({an identifier}) ! How are you?") + .setFrom("+15551231234") + .setDeliveryReport(DeliveryReportType.NONE) + .setSendAt(Instant.parse("2019-08-24T14:19:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:21:22Z")) + .setCallbackUrl("callback url") + .setClientReference("myReference") + .setFeedbackEnabled(false) + .setFlashMessage(true) + .setTruncateConcat(true) + .setMaxNumberOfMessageParts(1) + .setFromTon(6) + .setFromNpi(18) + .setParameters(parameters) + .build(); + + String serializedString = objectMapper.writeValueAsString(textRequestDTO); + + JSONAssert.assertEquals(jsonRequestTextDto, serializedString, true); + } + + @Test + void serializeMediaRequestDto() throws JsonProcessingException, JSONException { + + Map anIdentifierParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), + new AbstractMap.SimpleEntry<>("default", "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + MediaRequest mediaRequestDTO = + MediaRequest.builder() + .setTo(Arrays.asList("+15551231234", "+15551256344")) + .setBody( + MediaBody.builder() + .setUrl( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .setMessage("Hi ${name} ({an identifier}) ! How are you?") + .build()) + .setFrom("+15551231234") + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl("callback url") + .setClientReference("client reference") + .setFeedbackEnabled(false) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + + String serializedString = objectMapper.writeValueAsString(mediaRequestDTO); + + JSONAssert.assertEquals(jsonRequestMediaDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java new file mode 100644 index 000000000..388c040ba --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java @@ -0,0 +1,130 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.jupiter.api.Test; + +@TestWithResources +class SendBatchResponseDtoTest extends BaseTest { + @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + Batch loadedBinaryDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") + Batch loadedTextDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") + Batch loadedMediaDto; + + BatchBinary binaryResponseDto = + BatchBinary.builder() + .setBody("Hi ${name} ({an identifier}) ! How are you?") + .setCallbackUrl("callback url") + .setClientReference("myReference") + .setDeliveryReport(DeliveryReportType.NONE) + .setExpireAt(Instant.parse("2019-08-24T14:21:22Z")) + .setFeedbackEnabled(false) + .setFrom("+15551231234") + .setFromTon(6) + .setFromNpi(18) + .setSendAt(Instant.parse("2019-08-24T14:19:22Z")) + .setTo(Arrays.asList("+15551231234", "+15551256344")) + .setUdh("foo udh") + .setCanceled(false) + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setId("01FC66621XXXXX119Z8PMV1QPQ") + .build(); + + Map anIdentifierParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), + new AbstractMap.SimpleEntry<>("default", "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + BatchText textResponseDto = + BatchText.builder() + .setId("01FC66621XXXXX119Z8PMV1QPQ") + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setCanceled(false) + .setModifiedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setBody("Hi ${name} ({an identifier}) ! How are you?") + .setCallbackUrl("callback url") + .setClientReference("myReference") + .setDeliveryReport(DeliveryReportType.NONE) + .setExpireAt(Instant.parse("2019-08-24T14:21:22Z")) + .setFeedbackEnabled(false) + .setFlashMessage(true) + .setFrom("+15551231234") + .setFromTon(6) + .setFromNpi(18) + .setMaxNumberOfMessageParts(1) + .setParameters(parameters) + .setSendAt(Instant.parse("2019-08-24T14:19:22Z")) + .setTo(Arrays.asList("+15551231234", "+15551256344")) + .setTruncateConcat(true) + .build(); + + BatchMedia mediaResponseDto = + BatchMedia.builder() + .setId("01FC66621XXXXX119Z8PMV1QPQ") + .setCanceled(false) + .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setBody( + MediaBody.builder() + .setUrl( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .setMessage("Hi ${name} ({an identifier}) ! How are you?") + .build()) + .setCallbackUrl("callback url") + .setClientReference("client reference") + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setFeedbackEnabled(false) + .setFrom("+15551231234") + .setParameters(parameters) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setTo(Arrays.asList("+15551231234", "+15551256344")) + .setStrictValidation(true) + .build(); + + @Test + void deserializeBinary() { + + TestHelpers.recursiveEquals(loadedBinaryDto, binaryResponseDto); + } + + @Test + void deserializeText() { + + TestHelpers.recursiveEquals(loadedTextDto, textResponseDto); + } + + @Test + void deserializeMedia() { + + TestHelpers.recursiveEquals(loadedMediaDto, mediaResponseDto); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java new file mode 100644 index 000000000..2b14dc146 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java @@ -0,0 +1,68 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.io.IOException; +import java.util.AbstractMap; +import java.util.Collections; +import java.util.Map; +import java.util.logging.Logger; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class Send extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Send.class.getName()); + + public Send() throws IOException {} + + public static void main(String[] args) { + try { + new Send().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + + LOGGER.info("Send Text to " + phoneNumber); + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>(phoneNumber, "John"), + new AbstractMap.SimpleEntry<>("+12018888888", "Doe")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map codeParameters = + Stream.of(new AbstractMap.SimpleEntry<>(phoneNumber, "HALLOWEEN20 \uD83C\uDF83")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("code", codeParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + TextRequest.Builder builder = + TextRequest.builder() + .setTo(Collections.singletonList(phoneNumber)) + .setBody("Hello ${name}, this your code: ${code}") + .setClientReference("a client reference") + .setFrom("+33123456789") + .setParameters(parameters) + .setDeliveryReport(DeliveryReportType.FULL); + + // Overload default dashboard webhooks URL if defined + webhooksSmsPath.ifPresent(builder::setCallbackUrl); + + Batch value = service.send(builder.build()); + + LOGGER.info("Response: " + value); + } +} From 43b1f7d50140e45259d41dcf644c2bf043f90928 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 7 Dec 2024 10:38:03 +0100 Subject: [PATCH 08/65] feat (SMS/Batches): Support 'list' operation --- .../domains/sms/api/v1/BatchesService.java | 3 + .../sms/api/v1/adapters/BatchesService.java | 27 ++++ .../internal/SMSCursorPageNavigator.java | 35 +++++ .../batches/request/ListBatchesRequest.java | 141 ++++++++++++++++++ .../batches/response/ListBatchesResponse.java | 51 +++++++ .../sms/adapters/BatchesServiceTest.java | 6 +- .../internal/SMSCursorPageNavigatorTest.java | 26 ++++ .../v1/request/ListBatchesRequestTest.java | 57 +++++++ .../ListBatchesResponseDtoPage0.json | 0 .../ListBatchesResponseDtoPage1.json | 0 .../ListBatchesResponseDtoPage2.json | 0 .../com/sinch/sample/sms/v1/batches/List.java | 42 ++++++ 12 files changed, 385 insertions(+), 3 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java rename openapi-contracts/src/test/resources/domains/sms/v1/{ => batches/response}/ListBatchesResponseDtoPage0.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => batches/response}/ListBatchesResponseDtoPage1.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => batches/response}/ListBatchesResponseDtoPage2.json (100%) create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index beeb46f5b..51fd84f41 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -2,10 +2,13 @@ import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; public interface BatchesService { Batch send(BatchRequest batch) throws ApiException; + ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index c497e6210..0d12431c4 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -4,10 +4,16 @@ import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; +import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; import com.sinch.sdk.models.SmsContext; +import java.time.Instant; import java.util.Map; public class BatchesService implements com.sinch.sdk.domains.sms.api.v1.BatchesService { @@ -31,4 +37,25 @@ public Batch send(BatchRequest batch) throws ApiException { return getApi().send(batch); } + public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException { + + ListBatchesRequest guardParameters = + null != parameters ? parameters : ListBatchesRequest.builder().build(); + + ApiBatchList response = + getApi() + .list( + guardParameters.getPage().orElse(null), + guardParameters.getPageSize().orElse(null), + guardParameters.getFrom().orElse(null), + guardParameters.getStartDate().map(Instant::toString).orElse(null), + guardParameters.getEndDate().map(Instant::toString).orElse(null), + guardParameters.getClientReference().orElse(null)); + + SMSCursorPageNavigator navigator = + new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); + + return new ListBatchesResponse( + this, new Page<>(guardParameters, response.getBatches(), navigator)); + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java new file mode 100644 index 000000000..7e43e2c67 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java @@ -0,0 +1,35 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.internal; + +import com.sinch.sdk.core.models.pagination.PageNavigator; + +public class SMSCursorPageNavigator extends PageNavigator { + + private final Integer currentPage; + private final Integer pageSize; + + public SMSCursorPageNavigator(Integer currentPage, Integer pageSize) { + super(null); + this.currentPage = currentPage; + this.pageSize = pageSize; + } + + private Integer computeNextPageCursor() { + return null == pageSize || pageSize == 0 ? null : currentPage + 1; + } + + @Override + public Integer getToken() { + return computeNextPageCursor(); + } + + @Override + public String toString() { + return "SMSCursorPageNavigator{" + + "currentPage=" + + currentPage + + ", pageSize=" + + pageSize + + "} " + + super.toString(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java new file mode 100644 index 000000000..b6415dd14 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java @@ -0,0 +1,141 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; + +public class ListBatchesRequest { + + private final OptionalValue from; + private final OptionalValue startDate; + private final OptionalValue endDate; + private final OptionalValue clientReference; + private final OptionalValue page; + private final OptionalValue pageSize; + + private ListBatchesRequest( + OptionalValue from, + OptionalValue startDate, + OptionalValue endDate, + OptionalValue clientReference, + OptionalValue page, + OptionalValue pageSize) { + this.from = from; + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + this.page = page; + this.pageSize = pageSize; + } + + public OptionalValue getFrom() { + return from; + } + + public OptionalValue getStartDate() { + return startDate; + } + + public OptionalValue getEndDate() { + return endDate; + } + + public OptionalValue getClientReference() { + return clientReference; + } + + public OptionalValue getPage() { + return page; + } + + public OptionalValue getPageSize() { + return pageSize; + } + + public static Builder builder() { + return new Builder(); + } + + public static Builder builder(ListBatchesRequest parameters) { + return new Builder(parameters); + } + + public static class Builder { + + OptionalValue from = OptionalValue.empty(); + OptionalValue startDate = OptionalValue.empty(); + OptionalValue endDate = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + + private Builder() {} + + private Builder(ListBatchesRequest parameters) { + this.from = parameters.from; + this.startDate = parameters.startDate; + this.endDate = parameters.endDate; + this.clientReference = parameters.clientReference; + this.page = parameters.page; + this.pageSize = parameters.pageSize; + } + + /** + * @param from Only list messages sent from this sender number. Multiple originating numbers can + * be comma separated. Must be phone numbers or short code. + * @return current builder + */ + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + /** + * @param startDate Only list messages received at or after this date/time. + * @return current builder + */ + public Builder setStartDate(Instant startDate) { + this.startDate = OptionalValue.of(startDate); + return this; + } + + /** + * @param endDate Only list messages received before this date/time + * @return current builder + */ + public Builder setEndDate(Instant endDate) { + this.endDate = OptionalValue.of(endDate); + return this; + } + + /** + * @param clientReference Client reference to include + * @return current builder + */ + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + /** + * @param page The page number starting from 0 + * @return current builder + */ + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + /** + * @param pageSize Determines the size of a page + * @return current builder + */ + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public ListBatchesRequest build() { + return new ListBatchesRequest(from, startDate, endDate, clientReference, page, pageSize); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java new file mode 100644 index 000000000..34353487f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java @@ -0,0 +1,51 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import java.util.Collection; +import java.util.NoSuchElementException; + +public class ListBatchesResponse extends ListResponse { + + private final Page page; + private final BatchesService service; + private ListBatchesResponse nextPage; + + public ListBatchesResponse( + BatchesService service, Page page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + + if (null == nextPage) { + ListBatchesRequest.Builder newParameters = ListBatchesRequest.builder(page.getParameters()); + newParameters.setPage(page.getNextPageToken()); + nextPage = service.list(newParameters.build()); + } + return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); + } + + public ListBatchesResponse nextPage() { + + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + + ListBatchesResponse response = nextPage; + nextPage = null; + return response; + } + + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "ListBatchesResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index bbc1be71d..42aa8c19e 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -258,13 +258,13 @@ public class BatchesServiceTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") DryRun200ResponseDto dryRunResponseDto; - @GivenJsonResource("/domains/sms/v1/ListBatchesResponseDtoPage0.json") + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") ApiBatchListDto listBatchesResponseDtoPage0; - @GivenJsonResource("/domains/sms/v1/ListBatchesResponseDtoPage1.json") + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage1.json") ApiBatchListDto listBatchesResponseDtoPage1; - @GivenJsonResource("/domains/sms/v1/ListBatchesResponseDtoPage2.json") + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage2.json") ApiBatchListDto listBatchesResponseDtoPage2; @Mock SmsContext context; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java new file mode 100644 index 000000000..aafa8b01e --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java @@ -0,0 +1,26 @@ +package com.sinch.sdk.domains.sms.models.v1.internal; + +import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class SMSCursorPageNavigatorTest { + + @Test + void getTokenNullPageSize() { + SMSCursorPageNavigator cursorNavigator = new SMSCursorPageNavigator(45, null); + Assertions.assertThat(cursorNavigator.getToken()).isEqualTo(null); + } + + @Test + void getTokenZeroPageSize() { + SMSCursorPageNavigator cursorNavigator = new SMSCursorPageNavigator(45, 0); + Assertions.assertThat(cursorNavigator.getToken()).isEqualTo(null); + } + + @Test + void getToken() { + SMSCursorPageNavigator cursorNavigator = new SMSCursorPageNavigator(0, 15); + Assertions.assertThat(cursorNavigator.getToken()).isEqualTo(1); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java new file mode 100644 index 000000000..085a39e84 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java @@ -0,0 +1,57 @@ +package com.sinch.sdk.domains.sms.models.v1.request; + +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import java.time.Instant; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +class ListBatchesRequestTest { + + static final String from = "foo from"; + + static Instant startDate = Instant.now(); + static Instant endDate = Instant.now(); + static String clientReference = "a client reference"; + static Integer page = 1; + static Integer pageSize = 3; + + public static final ListBatchesRequest value = + ListBatchesRequest.builder() + .setFrom(from) + .setStartDate(startDate) + .setEndDate(endDate) + .setClientReference(clientReference) + .setPage(page) + .setPageSize(pageSize) + .build(); + + @Test + void getFrom() { + Assertions.assertThat(value.getFrom().get()).isEqualTo(from); + } + + @Test + void getStartDate() { + Assertions.assertThat(value.getStartDate().get()).isEqualTo(startDate); + } + + @Test + void getEndDate() { + Assertions.assertThat(value.getEndDate().get()).isEqualTo(endDate); + } + + @Test + void getClientReference() { + Assertions.assertThat(value.getClientReference().get()).isEqualTo(clientReference); + } + + @Test + void getPage() { + Assertions.assertThat(value.getPage().get()).isEqualTo(page); + } + + @Test + void getPageSize() { + Assertions.assertThat(value.getPageSize().get()).isEqualTo(pageSize); + } +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage0.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage0.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage1.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/ListBatchesResponseDtoPage1.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage1.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/ListBatchesResponseDtoPage1.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage2.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/ListBatchesResponseDtoPage2.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/ListBatchesResponseDtoPage2.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/ListBatchesResponseDtoPage2.json diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java new file mode 100644 index 000000000..6ee193456 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import java.io.IOException; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + LOGGER.info("List batches"); + + LOGGER.info("Response:"); + service + .list( + ListBatchesRequest.builder() + // .setFrom(phoneNumber) + // .setPage(15) + .setPageSize(2) + // .setClientReference("a client reference") + // .setStartDate(Instant.now()) + .build()) + .iterator() + .forEachRemaining(f -> LOGGER.info(f.toString())); + } +} From 4a1da86b0adb194e646c0dcb0382591e8a730ed6 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 7 Dec 2024 17:47:06 +0100 Subject: [PATCH 09/65] feat (SMS/Batches): Support 'dryRun' operation --- .../domains/sms/api/v1/BatchesService.java | 3 ++ .../sms/api/v1/adapters/BatchesService.java | 5 +++ .../sms/adapters/BatchesServiceTest.java | 2 +- .../converters/DryRunDtoConverterTest.java | 2 +- .../models/dto/v1/DryRunResponseDtoTest.java | 4 +- .../response/DryRunResponseDtoTest.java | 35 ++++++++++++++++ .../response}/DryRunResponseDto.json | 0 .../sinch/sample/sms/v1/batches/dryRun.java | 42 +++++++++++++++++++ 8 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseDtoTest.java rename openapi-contracts/src/test/resources/domains/sms/v1/{ => batches/response}/DryRunResponseDto.json (100%) create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 51fd84f41..04434473f 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -4,6 +4,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; public interface BatchesService { @@ -11,4 +12,6 @@ public interface BatchesService { Batch send(BatchRequest batch) throws ApiException; ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; + + DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index 0d12431c4..f22b2e17d 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -10,6 +10,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; import com.sinch.sdk.models.SmsContext; @@ -58,4 +59,8 @@ public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiExcepti return new ListBatchesResponse( this, new Page<>(guardParameters, response.getBatches(), navigator)); } + + public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch) { + return getApi().dryRun(perRecipient, numberOfRecipient, batch); + } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index 42aa8c19e..493f389fa 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -255,7 +255,7 @@ public class BatchesServiceTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") SendSMS201ResponseDto textResponseDto; - @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") DryRun200ResponseDto dryRunResponseDto; @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java index 4f53ccaa1..7b262f973 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DryRunDtoConverterTest.java @@ -13,7 +13,7 @@ @TestWithResources public class DryRunDtoConverterTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") DryRun200ResponseDto loadedDto; public static DryRun dryRunClient = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java index 5150bad2f..c17327964 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DryRunResponseDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources class DryRunResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/DryRunResponseDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") DryRun200ResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/DryRunResponseDto.json") + @GivenTextResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") String jsonStringDto; DryRun200ResponseDto dto = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseDtoTest.java new file mode 100644 index 000000000..ae46b43bd --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseDtoTest.java @@ -0,0 +1,35 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import java.util.Collections; +import org.junit.jupiter.api.Test; + +@TestWithResources +class DryRunResponseDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") + DryRunResponse loadedDto; + + DryRunResponse dto = + DryRunResponse.builder() + .setNumberOfRecipients(123) + .setNumberOfMessages(456) + .setPerRecipient( + Collections.singletonList( + DryRunPerRecipientDetails.builder() + .setRecipient("recipient string") + .setNumberOfParts(1) + .setBody("body string") + .setEncoding("encoding string") + .build())) + .build(); + + @Test + void deserialize() { + + TestHelpers.recursiveEquals(loadedDto, dto); + } +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/DryRunResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/DryRunResponseDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/DryRunResponseDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/DryRunResponseDto.json diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java new file mode 100644 index 000000000..7fd0c48be --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class dryRun extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(dryRun.class.getName()); + + public dryRun() throws IOException {} + + public static void main(String[] args) { + try { + new dryRun().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + LOGGER.info("DryRun Request"); + + DryRunResponse value = + service.dryRun( + true, + 3, + TextRequest.builder() + .setTo(Collections.singletonList(phoneNumber)) + .setBody("the body") + .build()); + + LOGGER.info("Response: " + value); + } +} From 304b55e69e1283c1a31be54070640d8b9fbc67bd Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sun, 8 Dec 2024 14:47:50 +0100 Subject: [PATCH 10/65] feat (SMS/Batches): Support 'get' operation --- .../domains/sms/api/v1/BatchesService.java | 2 ++ .../sms/api/v1/adapters/BatchesService.java | 4 +++ .../com/sinch/sample/sms/v1/batches/Get.java | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 04434473f..77e02a2d0 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -14,4 +14,6 @@ public interface BatchesService { ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); + + Batch get(String batchId) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index f22b2e17d..fd65d506a 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -63,4 +63,8 @@ public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiExcepti public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch) { return getApi().dryRun(perRecipient, numberOfRecipient, batch); } + + public Batch get(String batchId) throws ApiException { + return getApi().get(batchId); + } } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java new file mode 100644 index 000000000..2f3ea499e --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java @@ -0,0 +1,32 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + LOGGER.info("Get for :" + batchId); + + Batch value = service.get(batchId); + + LOGGER.info("Response :" + value); + } +} From 9cd60f4b44b9e6d7d0c747928ff9c34daf58ac1d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 9 Dec 2024 06:22:17 +0100 Subject: [PATCH 11/65] feat (SMS/Batches): Support 'replace' operation --- .../domains/sms/api/v1/BatchesService.java | 2 + .../sms/api/v1/adapters/BatchesService.java | 4 ++ .../sinch/sample/sms/v1/batches/Replace.java | 42 +++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 77e02a2d0..7ef86fb8e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -16,4 +16,6 @@ public interface BatchesService { DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); Batch get(String batchId) throws ApiException; + + Batch replace(String batchId, BatchRequest batch) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index fd65d506a..27294d170 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -67,4 +67,8 @@ public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchR public Batch get(String batchId) throws ApiException { return getApi().get(batchId); } + + public Batch replace(String batchId, BatchRequest batch) throws ApiException { + return getApi().replace(batchId, batch); + } } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java new file mode 100644 index 000000000..cfb10d906 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java @@ -0,0 +1,42 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Replace extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Replace.class.getName()); + + public Replace() throws IOException {} + + public static void main(String[] args) { + try { + new Replace().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + + LOGGER.info("Replace batch" + batchId); + Batch value = + service.replace( + batchId, + TextRequest.builder() + .setTo(Collections.singletonList("+33745149803")) + .setBody("the body") + .setClientReference("a client reference") + .setFrom("+33123456789") + .build()); + + LOGGER.info("Response: " + value); + } +} From d2d588a50fe5ea1ddc40b4deb2c611ffe88d61ed Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 9 Dec 2024 06:23:28 +0100 Subject: [PATCH 12/65] feat (SMS/Batches): Support 'cancel' operation --- .../domains/sms/api/v1/BatchesService.java | 2 ++ .../sms/api/v1/adapters/BatchesService.java | 4 +++ .../sinch/sample/sms/v1/batches/Cancel.java | 32 +++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 7ef86fb8e..005fb812d 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -18,4 +18,6 @@ public interface BatchesService { Batch get(String batchId) throws ApiException; Batch replace(String batchId, BatchRequest batch) throws ApiException; + + Batch cancel(String batchId) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index 27294d170..bbe6331c0 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -71,4 +71,8 @@ public Batch get(String batchId) throws ApiException { public Batch replace(String batchId, BatchRequest batch) throws ApiException { return getApi().replace(batchId, batch); } + + public Batch cancel(String batchId) throws ApiException { + return getApi().cancel(batchId); + } } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java new file mode 100644 index 000000000..7726f1d72 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java @@ -0,0 +1,32 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.io.IOException; +import java.util.logging.Logger; + +public class Cancel extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Cancel.class.getName()); + + public Cancel() throws IOException {} + + public static void main(String[] args) { + try { + new Cancel().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + + LOGGER.info("Cancelling batch: " + batchId); + Batch value = service.cancel(batchId); + + LOGGER.info("Response: " + value); + } +} From 43a52140a2bcb566e3b72bb110e0dcaa2a672ac8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 9 Dec 2024 06:38:40 +0100 Subject: [PATCH 13/65] feat (SMS/Batches): Support 'sendDeliveryFeedback' operation --- .../domains/sms/api/v1/BatchesService.java | 4 ++ .../sms/api/v1/adapters/BatchesService.java | 6 +++ .../SendDeliveryFeedbackRequestTest.java | 29 ++++++++++++++ .../SendDeliveryFeedbackRequestDto.json | 6 +++ .../sms/v1/batches/SendDeliveryFeedback.java | 38 +++++++++++++++++++ 5 files changed, 83 insertions(+) create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 005fb812d..37cdd79b4 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -3,6 +3,7 @@ import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; @@ -20,4 +21,7 @@ public interface BatchesService { Batch replace(String batchId, BatchRequest batch) throws ApiException; Batch cancel(String batchId) throws ApiException; + + void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest recipients) + throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index bbe6331c0..dbef32214 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -9,6 +9,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; @@ -75,4 +76,9 @@ public Batch replace(String batchId, BatchRequest batch) throws ApiException { public Batch cancel(String batchId) throws ApiException { return getApi().cancel(batchId); } + + public void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest request) + throws ApiException { + getApi().sendDeliveryFeedback(batchId, request); + } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java new file mode 100644 index 000000000..581da9688 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java @@ -0,0 +1,29 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class SendDeliveryFeedbackRequestTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json") + String jsonSendDeliveryFeedbackRequestDto; + + @Test + void sendDeliveryFeedbackRequestRequestDto() throws JsonProcessingException, JSONException { + + SendDeliveryFeedbackRequest requestDTO = + SendDeliveryFeedbackRequest.builder() + .setRecipients(Arrays.asList("foo number 1", "foo number 2")) + .build(); + + String serializedString = objectMapper.writeValueAsString(requestDTO); + + JSONAssert.assertEquals(jsonSendDeliveryFeedbackRequestDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json new file mode 100644 index 000000000..be9141af0 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json @@ -0,0 +1,6 @@ +{ + "recipients": [ + "foo number 1", + "foo number 2" + ] +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java new file mode 100644 index 000000000..ab89da20e --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java @@ -0,0 +1,38 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import java.io.IOException; +import java.util.Arrays; +import java.util.logging.Logger; + +public class SendDeliveryFeedback extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(SendDeliveryFeedback.class.getName()); + + public SendDeliveryFeedback() throws IOException {} + + public static void main(String[] args) { + try { + new SendDeliveryFeedback().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + + LOGGER.info("Send Delivery Feedback for batch ID:" + batchId); + + SendDeliveryFeedbackRequest request = + SendDeliveryFeedbackRequest.builder() + .setRecipients(Arrays.asList("foo number 1", "foo number 2")) + .build(); + service.sendDeliveryFeedback(batchId, request); + LOGGER.info("Done"); + } +} From aa4223eddc72d086540d9c4756dbc6b1609dea28 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 9 Dec 2024 15:45:45 +0100 Subject: [PATCH 14/65] feat (SMS/Batches): Support 'update' operation --- .../domains/sms/api/v1/BatchesService.java | 3 + .../sms/api/v1/adapters/BatchesService.java | 5 + .../batches/request/UpdateBatchRequest.java | 3 + .../request/UpdateBatchRequestDtoTest.java | 130 ++++++++++++++++++ .../request/UpdateBinaryRequestDto.json | 22 +++ .../request/UpdateMediaRequestDto.json | 34 +++++ .../batches/request/UpdateTextRequestDto.json | 35 +++++ .../sinch/sample/sms/v1/batches/Update.java | 44 ++++++ 8 files changed, 276 insertions(+) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateBinaryRequestDto.json create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateMediaRequestDto.json create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateTextRequestDto.json create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 37cdd79b4..449491e4c 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -4,6 +4,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; @@ -24,4 +25,6 @@ public interface BatchesService { void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest recipients) throws ApiException; + + Batch update(String batchId, UpdateBatchRequest request) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index dbef32214..e32033317 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -10,6 +10,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; @@ -81,4 +82,8 @@ public void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest req throws ApiException { getApi().sendDeliveryFeedback(batchId, request); } + + public Batch update(String batchId, UpdateBatchRequest request) throws ApiException { + return getApi().update(batchId, request); + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java new file mode 100644 index 000000000..80cd64316 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java @@ -0,0 +1,3 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +public interface UpdateBatchRequest {} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java new file mode 100644 index 000000000..e74d2f92a --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java @@ -0,0 +1,130 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class UpdateBatchRequestDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/batches/request/UpdateBinaryRequestDto.json") + String jsonRequestBinaryDto; + + @GivenTextResource("/domains/sms/v1/batches/request/UpdateTextRequestDto.json") + String jsonRequestTextDto; + + @GivenTextResource("/domains/sms/v1/batches/request/UpdateMediaRequestDto.json") + String jsonRequestMediaDto; + + Map anIdentifierParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), + new AbstractMap.SimpleEntry<>("default", "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + @Test + void serializeBinaryRequestDto() throws JsonProcessingException, JSONException { + + UpdateBinaryRequest binaryRequestDTO = + UpdateBinaryRequest.builder() + .setFrom("+15551231234") + .setToAdd(Arrays.asList("+15551231234", "+15987365412")) + .setToRemove(Arrays.asList("+0123456789", "+9876543210")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2019-08-24T14:19:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:21:22Z")) + .setCallbackUrl("callback url") + .setClientReference("a client reference") + .setFeedbackEnabled(true) + .setBody("Hi ${name} ({an identifier}) ! How are you?") + .setUdh("foo udh") + .setFromTon(3) + .setFromNpi(10) + .build(); + + String serializedString = objectMapper.writeValueAsString(binaryRequestDTO); + + JSONAssert.assertEquals(jsonRequestBinaryDto, serializedString, true); + } + + @Test + void serializeTextRequestDto() throws JsonProcessingException, JSONException { + + UpdateTextRequest textRequestDTO = + UpdateTextRequest.builder() + .setFrom("+15551231234") + .setToAdd(Arrays.asList("+15551231234", "+15551256344")) + .setToRemove(Arrays.asList("+0123456789", "+9876543210")) + .setDeliveryReport(DeliveryReportType.NONE) + .setSendAt(Instant.parse("2019-08-24T14:19:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:21:22Z")) + .setCallbackUrl("callback url") + .setClientReference("a client reference") + .setFeedbackEnabled(true) + .setParameters(parameters) + .setBody("Hi ${name} ({an identifier}) ! How are you?") + .setFromTon(3) + .setFromNpi(15) + .setMaxNumberOfMessageParts(4) + .setTruncateConcat(true) + .setFlashMessage(false) + .build(); + + String serializedString = objectMapper.writeValueAsString(textRequestDTO); + + JSONAssert.assertEquals(jsonRequestTextDto, serializedString, true); + } + + @Test + void serializeMediaRequestDto() throws JsonProcessingException, JSONException { + + UpdateMediaRequest mediaRequestDTO = + UpdateMediaRequest.builder() + .setFrom("+15551231234") + .setToAdd(Arrays.asList("+15551231234", "+15987365412")) + .setToRemove(Arrays.asList("+0123456789", "+9876543210")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl("callback url") + .setClientReference("a client reference") + .setFeedbackEnabled(true) + .setBody( + MediaBody.builder() + .setUrl( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .setMessage("Hi ${name} ({an identifier}) ! How are you?") + .build()) + .setParameters(parameters) + .setStrictValidation(true) + .build(); + + String serializedString = objectMapper.writeValueAsString(mediaRequestDTO); + + JSONAssert.assertEquals(jsonRequestMediaDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateBinaryRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateBinaryRequestDto.json new file mode 100644 index 000000000..222756713 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateBinaryRequestDto.json @@ -0,0 +1,22 @@ +{ + "to_add": [ + "+15551231234", + "+15987365412" + ], + "to_remove": [ + "+0123456789", + "+9876543210" + ], + "from": "+15551231234", + "type": "mt_binary", + "delivery_report": "full", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "client_reference": "a client reference", + "feedback_enabled": true, + "body": "Hi ${name} ({an identifier}) ! How are you?", + "udh": "foo udh", + "from_ton": 3, + "from_npi": 10 +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateMediaRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateMediaRequestDto.json new file mode 100644 index 000000000..97595c06d --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateMediaRequestDto.json @@ -0,0 +1,34 @@ +{ + "to_add": [ + "+15551231234", + "+15987365412" + ], + "to_remove": [ + "+0123456789", + "+9876543210" + ], + "from": "+15551231234", + "body": { + "message": "Hi ${name} ({an identifier}) ! How are you?", + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" + }, + "parameters": { + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", + "default": "default value" + }, + "an identifier": { + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" + } + }, + "type": "mt_media", + "delivery_report": "summary", + "send_at": "2019-08-24T14:16:22Z", + "expire_at": "2019-08-24T14:17:22Z", + "callback_url": "callback url", + "client_reference": "a client reference", + "feedback_enabled": true, + "strict_validation": true +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateTextRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateTextRequestDto.json new file mode 100644 index 000000000..4576d17c7 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/UpdateTextRequestDto.json @@ -0,0 +1,35 @@ +{ + "to_add": [ + "+15551231234", + "+15551256344" + ], + "to_remove": [ + "+0123456789", + "+9876543210" + ], + "from": "+15551231234", + "body": "Hi ${name} ({an identifier}) ! How are you?", + "type": "mt_text", + "delivery_report": "none", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "client_reference": "a client reference", + "feedback_enabled": true, + "from_ton": 3, + "from_npi": 15, + "flash_message": false, + "max_number_of_message_parts": 4, + "truncate_concat": true, + "parameters": { + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", + "default": "default value" + }, + "an identifier": { + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" + } + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java new file mode 100644 index 000000000..2cd84e5e0 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java @@ -0,0 +1,44 @@ +package com.sinch.sample.sms.v1.batches; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.io.IOException; +import java.util.Collections; +import java.util.logging.Logger; + +public class Update extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Update.class.getName()); + + public Update() throws IOException {} + + public static void main(String[] args) { + try { + new Update().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + BatchesService service = client.sms().v1().batches(); + + LOGGER.info("Updating batch: " + batchId); + + UpdateTextRequest.Builder builder = + UpdateTextRequest.builder() + .setToRemove(Collections.singletonList("+33745149803")) + .setToAdd(Collections.singletonList("+33745149803")) + .setBody("the body updated") + .setFrom("+33123456789"); + + webhooksSmsPath.ifPresent(builder::setCallbackUrl); + + Batch value = service.update(batchId, builder.build()); + + LOGGER.info("Response: " + value); + } +} From 7d3cce1dbedcdd840b674b6cf226e9d26893e681 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 9 Dec 2024 16:37:10 +0100 Subject: [PATCH 15/65] refactor (SMS/Batches): 'flash_message', 'truncat_concat' and 'max_number_of_parts' field deprecation for Send Binary Message --- .../requests/SendSmsBatchBinaryRequest.java | 3 +++ .../converters/BatchDtoConverterTest.java | 2 +- .../models/dto/v1/SendSMSRequestDtoTest.java | 2 +- .../domains/sms/v1/BinaryRequestDto.json | 21 +++++++++++++++++++ .../v1/batches/request/BinaryRequestDto.json | 3 --- 5 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/BinaryRequestDto.json diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java index b0f17ee44..a3b2ce2f6 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/requests/SendSmsBatchBinaryRequest.java @@ -112,6 +112,7 @@ private Builder() { /** * @param flashMessage If sent as a flash message, displays true. * @return current builder + * @deprecated */ public Builder setFlashMessage(boolean flashMessage) { this.flashMessage = OptionalValue.of(flashMessage); @@ -121,6 +122,7 @@ public Builder setFlashMessage(boolean flashMessage) { /** * @param truncateConcat If set to true, the message was shortened when exceeding one part. * @return current builder + * @deprecated */ public Builder setTruncateConcat(boolean truncateConcat) { this.truncateConcat = OptionalValue.of(truncateConcat); @@ -130,6 +132,7 @@ public Builder setTruncateConcat(boolean truncateConcat) { /** * @param maxNumberOfMessageParts Displays the number of message parts set in the request. * @return current builder + * @deprecated */ public Builder setMaxNumberOfMessageParts(int maxNumberOfMessageParts) { this.maxNumberOfMessageParts = OptionalValue.of(maxNumberOfMessageParts); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java index 7c9e2473d..9647a6324 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java @@ -36,7 +36,7 @@ class BatchDtoConverterTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") public SendSMS201ResponseDto mediaResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/request/BinaryRequestDto.json") + @GivenJsonResource("/domains/sms/v1/BinaryRequestDto.json") public SendSMSRequestDto sendBinaryRequestDto; @GivenJsonResource("/domains/sms/v1/batches/request/TextRequestDto.json") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java index 3be96cf8c..d7361cfd9 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java @@ -16,7 +16,7 @@ @TestWithResources class SendSMSRequestDtoTest extends BaseTest { - @GivenTextResource("/domains/sms/v1/batches/request/BinaryRequestDto.json") + @GivenTextResource("/domains/sms/v1/BinaryRequestDto.json") String jsonRequestBinaryDto; @GivenTextResource("/domains/sms/v1/batches/request/TextRequestDto.json") diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/BinaryRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/BinaryRequestDto.json new file mode 100644 index 000000000..04609a490 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/BinaryRequestDto.json @@ -0,0 +1,21 @@ +{ + "to": [ + "+15551231234", + "+15551256344" + ], + "from": "+15551231234", + "body": "Hi ${name} ({an identifier}) ! How are you?", + "type": "mt_binary", + "delivery_report": "none", + "send_at": "2019-08-24T14:19:22Z", + "expire_at": "2019-08-24T14:21:22Z", + "callback_url": "callback url", + "client_reference": "myReference", + "feedback_enabled": false, + "flash_message": true, + "truncate_concat": true, + "max_number_of_message_parts": 1, + "from_ton": 6, + "from_npi": 18, + "udh": "foo udh" +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/BinaryRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/BinaryRequestDto.json index 04609a490..caf327e09 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/BinaryRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/BinaryRequestDto.json @@ -12,9 +12,6 @@ "callback_url": "callback url", "client_reference": "myReference", "feedback_enabled": false, - "flash_message": true, - "truncate_concat": true, - "max_number_of_message_parts": 1, "from_ton": 6, "from_npi": 18, "udh": "foo udh" From 56ac119a09ea44991e2eadea4f0929253c58b32a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 14 Dec 2024 11:49:17 +0100 Subject: [PATCH 16/65] refactor (SMS/Batche): Support new 'subject' field for MediaMessage --- .../models/dto/v1/MediaResponseDtoTest.java | 15 ------- .../models/dto/v1/SendSMSRequestDtoTest.java | 2 +- .../models/v1/batches/MediaBodyDtoTest.java | 41 +++++++++++++++++++ .../request/SendBatchRequestDtoTest.java | 9 +--- .../response/SendBatchResponseDtoTest.java | 9 +--- .../domains/sms/v1/MediaRequestDto.json | 30 ++++++++++++++ .../domains/sms/v1/batches/MediaBodyDto.json | 5 +++ .../v1/batches/request/MediaRequestDto.json | 3 +- .../v1/batches/response/BatchMediaDto.json | 3 +- 9 files changed, 85 insertions(+), 32 deletions(-) create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyDtoTest.java create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/MediaRequestDto.json create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/batches/MediaBodyDto.json diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java index 4880cfcf1..2bf8b5951 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java @@ -1,9 +1,7 @@ package com.sinch.sdk.domains.sms.models.dto.v1; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; -import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.fasterxml.jackson.core.JsonProcessingException; import com.sinch.sdk.BaseTest; import java.time.OffsetDateTime; import java.util.AbstractMap; @@ -12,19 +10,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.assertj.core.api.Assertions; -import org.json.JSONException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources class MediaResponseDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") MediaResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/batches/response/BatchMediaDto.json") - String jsonStringDto; - ParameterObjDto parameterObjDto = new ParameterObjDto(); MediaResponseDto mediaDTO = @@ -56,14 +49,6 @@ void deserialize() { Assertions.assertThat(loadedDto).usingRecursiveComparison().isEqualTo(mediaDTO); } - @Test - void serialize() throws JsonProcessingException, JSONException { - - String serializedString = objectMapper.writeValueAsString(mediaDTO); - - JSONAssert.assertEquals(jsonStringDto, serializedString, true); - } - @BeforeEach void setUp() { parameterObjDto.put( diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java index d7361cfd9..d9caae8a5 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSRequestDtoTest.java @@ -22,7 +22,7 @@ class SendSMSRequestDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/batches/request/TextRequestDto.json") String jsonRequestTextDto; - @GivenTextResource("/domains/sms/v1/batches/request/MediaRequestDto.json") + @GivenTextResource("/domains/sms/v1/MediaRequestDto.json") String jsonRequestMediaDto; @Test diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyDtoTest.java new file mode 100644 index 000000000..de3daff13 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyDtoTest.java @@ -0,0 +1,41 @@ +package com.sinch.sdk.domains.sms.models.v1.batches; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class MediaBodyDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/batches/MediaBodyDto.json") + String jsonMediaBodyDto; + + @GivenJsonResource("/domains/sms/v1/batches/MediaBodyDto.json") + MediaBody loadedMediaBodyDto; + + public static final MediaBody mediaBodyDto = + MediaBody.builder() + .setSubject("subject field") + .setUrl("https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .setMessage("Hi ${name} ({an identifier}) ! How are you?") + .build(); + + @Test + void serialize() throws JsonProcessingException, JSONException { + + String serializedString = objectMapper.writeValueAsString(mediaBodyDto); + + JSONAssert.assertEquals(jsonMediaBodyDto, serializedString, true); + } + + @Test + void deserialize() { + + TestHelpers.recursiveEquals(loadedMediaBodyDto, mediaBodyDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java index 948deeb10..6e473a46d 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java @@ -5,7 +5,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.sinch.sdk.BaseTest; import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; -import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest; import java.time.Instant; import java.util.AbstractMap; import java.util.Arrays; @@ -122,12 +122,7 @@ void serializeMediaRequestDto() throws JsonProcessingException, JSONException { MediaRequest mediaRequestDTO = MediaRequest.builder() .setTo(Arrays.asList("+15551231234", "+15551256344")) - .setBody( - MediaBody.builder() - .setUrl( - "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .setMessage("Hi ${name} ({an identifier}) ! How are you?") - .build()) + .setBody(MediaBodyDtoTest.mediaBodyDto) .setFrom("+15551231234") .setDeliveryReport(DeliveryReportType.SUMMARY) .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java index 388c040ba..ab5f6c325 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java @@ -5,7 +5,7 @@ import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; -import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest; import java.time.Instant; import java.util.AbstractMap; import java.util.Arrays; @@ -92,12 +92,7 @@ class SendBatchResponseDtoTest extends BaseTest { .setCanceled(false) .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) .setModifiedAt(Instant.parse("2019-08-24T14:15:22Z")) - .setBody( - MediaBody.builder() - .setUrl( - "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .setMessage("Hi ${name} ({an identifier}) ! How are you?") - .build()) + .setBody(MediaBodyDtoTest.mediaBodyDto) .setCallbackUrl("callback url") .setClientReference("client reference") .setDeliveryReport(DeliveryReportType.SUMMARY) diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/MediaRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/MediaRequestDto.json new file mode 100644 index 000000000..b9622412d --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/MediaRequestDto.json @@ -0,0 +1,30 @@ +{ + "to": [ + "+15551231234", + "+15551256344" + ], + "from": "+15551231234", + "body": { + "message": "Hi ${name} ({an identifier}) ! How are you?", + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" + }, + "parameters": { + "name": { + "15551231234": "name value for 15551231234", + "15551256344": "name value for 15551256344", + "default": "default value" + }, + "an identifier": { + "15551231234": "an identifier value for 15551231234", + "15551256344": "an identifier value for 15551256344" + } + }, + "type": "mt_media", + "delivery_report": "summary", + "send_at": "2019-08-24T14:16:22Z", + "expire_at": "2019-08-24T14:17:22Z", + "callback_url": "callback url", + "client_reference": "client reference", + "feedback_enabled": false, + "strict_validation": true +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/MediaBodyDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/MediaBodyDto.json new file mode 100644 index 000000000..22a59e621 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/MediaBodyDto.json @@ -0,0 +1,5 @@ +{ + "subject": "subject field", + "message": "Hi ${name} ({an identifier}) ! How are you?", + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/MediaRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/MediaRequestDto.json index b9622412d..d48fc1e55 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/MediaRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/MediaRequestDto.json @@ -6,7 +6,8 @@ "from": "+15551231234", "body": { "message": "Hi ${name} ({an identifier}) ! How are you?", - "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", + "subject": "subject field" }, "parameters": { "name": { diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json index 91949c129..7c1143b41 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json @@ -8,7 +8,8 @@ "canceled": false, "body": { "message": "Hi ${name} ({an identifier}) ! How are you?", - "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png" + "url": "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png", + "subject": "subject field" }, "parameters": { "name": { From 8d8a7e3630402a60d5b50733935e76da88056417 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 16 Dec 2024 07:36:00 +0100 Subject: [PATCH 17/65] CI: CODEOWNERS file cleanup --- .github/CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c9dc4b9f0..45c9f71f2 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,2 +1,2 @@ # https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners -* @Dovchik @650elx @krogers0607 @asein-sinch @JPPortier +* @Dovchik @krogers0607 @asein-sinch @JPPortier From 858ea5e24f4e65a53d7996d0cbc4a8de0667bd06 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 14 Dec 2024 11:51:12 +0100 Subject: [PATCH 18/65] test (SMS/Batches): Add IT and e2e tests for V1 --- .../api/v1/adapters/BatchesServiceTest.java | 509 ++++++++++++++++++ .../sms/api/v1/adapters/SMSServiceTest.java | 83 +++ .../sdk/e2e/domains/sms/v1/BatchesSteps.java | 404 ++++++++++++++ .../sinch/sdk/e2e/domains/sms/v1/SmsIT.java | 16 + pom.xml | 1 + 5 files changed, 1013 insertions(+) create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java new file mode 100644 index 000000000..6a66dfaf7 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java @@ -0,0 +1,509 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.BinaryRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.MediaRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBinaryRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateMediaRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchBinary; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchMedia; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchText; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; +import com.sinch.sdk.models.SmsContext; +import java.time.Instant; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; + +@TestWithResources +public class BatchesServiceTest extends BaseTest { + + static final String id = "01FC66621XXXXX119Z8PMV1QPQ"; + static final List to = Arrays.asList("+15551231234", "+15551256344"); + static final String from = "+15551231234"; + static final boolean canceled = false; + static final Instant createdAt = Instant.parse("2019-08-24T14:15:22Z"); + static final Instant modifiedAt = Instant.parse("2019-08-24T14:17:22Z"); + static final DeliveryReportType deliveryReport = DeliveryReportType.NONE; + static final Instant sendAt = Instant.parse("2019-08-24T14:19:22Z"); + static final Instant expireAt = Instant.parse("2019-08-24T14:21:22Z"); + static final String callbackUrl = "callback url"; + static final String clientReference = "myReference"; + static final boolean flashMessage = true; + static final boolean feedbackEnabled = false; + static final boolean truncateConcat = true; + static final int maxNumberOfMessageParts = 1; + static final int fromTon = 6; + static final int fromNpi = 18; + static final String udh = "foo udh"; + static final String body = "Hi ${name} ({an identifier}) ! How are you?"; + public static final BatchBinary batchBinary = + BatchBinary.builder() + .setId(id) + .setTo(to) + .setFrom(from) + .setCanceled(canceled) + .setBody(body) + .setCreatedAt(createdAt) + .setModifiedAt(modifiedAt) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setClientReference(clientReference) + .setFeedbackEnabled(feedbackEnabled) + .setFromTon(fromTon) + .setFromNpi(fromNpi) + .setUdh(udh) + .build(); + + static final Map anIdentifierParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + static final Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), + new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), + new AbstractMap.SimpleEntry<>("default", "default value")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + static final Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + public static final BatchMedia batchMedia = + BatchMedia.builder() + .setId(id) + .setTo(to) + .setFrom(from) + .setCanceled(canceled) + .setBody( + MediaBody.builder() + .setSubject("subject field") + .setUrl( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .setMessage("Hi ${name} ({an identifier}) ! How are you?") + .build()) + .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl(callbackUrl) + .setClientReference("client reference") + .setFeedbackEnabled(feedbackEnabled) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + public static final BatchText batchText = + BatchText.builder() + .setId(id) + .setTo(to) + .setFrom(from) + .setCanceled(canceled) + .setBody(body) + .setCreatedAt(createdAt) + .setModifiedAt(modifiedAt) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setClientReference(clientReference) + .setFlashMessage(flashMessage) + .setFeedbackEnabled(feedbackEnabled) + .setTruncateConcat(truncateConcat) + .setMaxNumberOfMessageParts(maxNumberOfMessageParts) + .setFromTon(fromTon) + .setFromNpi(fromNpi) + .setParameters(parameters) + .build(); + + public static final BinaryRequest sendSmsBatchBinaryRequest = + BinaryRequest.builder() + .setTo(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setClientReference(clientReference) + .setFeedbackEnabled(feedbackEnabled) + .setFromTon(fromTon) + .setFromNpi(fromNpi) + .setUdh(udh) + .build(); + + public static final MediaRequest sendSmsBatchMediaRequest = + MediaRequest.builder() + .setTo(to) + .setFrom(from) + .setBody( + MediaBody.builder() + .setUrl( + "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") + .setMessage("Hi ${name} ({an identifier}) ! How are you?") + .build()) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl(callbackUrl) + .setClientReference("client reference") + .setFeedbackEnabled(feedbackEnabled) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + public static final TextRequest sendSmsBatchTextRequest = + TextRequest.builder() + .setTo(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setClientReference(clientReference) + .setFlashMessage(flashMessage) + .setFeedbackEnabled(feedbackEnabled) + .setTruncateConcat(truncateConcat) + .setMaxNumberOfMessageParts(maxNumberOfMessageParts) + .setFromTon(fromTon) + .setFromNpi(fromNpi) + .setParameters(parameters) + .build(); + + public static final UpdateTextRequest updateSmsBatchTextRequest = + UpdateTextRequest.builder() + .setToAdd(to) + .setFrom(from) + .setBody(body) + .setDeliveryReport(deliveryReport) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setParameters(parameters) + .build(); + + public static final UpdateMediaRequest updateSmsBatchMediaRequest = + UpdateMediaRequest.builder() + .setToRemove(to) + .setFrom(from) + .setBody(MediaBodyDtoTest.mediaBodyDto) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) + .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) + .setCallbackUrl(callbackUrl) + .setStrictValidation(true) + .setParameters(parameters) + .build(); + + public static final UpdateBinaryRequest updateSmsBatchBinaryRequest = + UpdateBinaryRequest.builder() + .setToAdd(Arrays.asList("+15551231234", "+15987365412")) + .setToRemove(Arrays.asList("+0123456789", "+9876543210")) + .setFrom(from) + .setBody(body) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(sendAt) + .setExpireAt(expireAt) + .setCallbackUrl(callbackUrl) + .setUdh(udh) + .build(); + + @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + public Batch binaryResponseDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") + Batch mediaResponseDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") + Batch textResponseDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") + DryRunResponse dryRunResponseDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") + ApiBatchList listBatchesResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage1.json") + ApiBatchList listBatchesResponseDtoPage1; + + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage2.json") + ApiBatchList listBatchesResponseDtoPage2; + + @Mock SmsContext context; + @Mock HttpClient httpClient; + @Mock Map authManagers; + @Mock BatchesApi api; + BatchesService service; + String uriPartID = "foovalue"; + + @Captor ArgumentCaptor recipientsCaptor; + + @BeforeEach + public void initMocks() { + service = spy(new BatchesService(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @Test + void getBinary() throws ApiException { + + when(api.get(eq("foo binary batch id"))).thenReturn(binaryResponseDto); + + Batch response = service.get("foo binary batch id"); + + TestHelpers.recursiveEquals(response, batchBinary); + } + + @Test + void getMedia() throws ApiException { + + when(api.get(eq("foo media batch id"))).thenReturn(mediaResponseDto); + + Batch response = service.get("foo media batch id"); + + TestHelpers.recursiveEquals(response, batchMedia); + } + + @Test + void getText() throws ApiException { + + when(api.get(eq("foo text batch id"))).thenReturn(textResponseDto); + + Batch response = service.get("foo text batch id"); + + TestHelpers.recursiveEquals(response, batchText); + } + + @Test + void sendBinary() throws ApiException { + + when(api.send(sendSmsBatchBinaryRequest)).thenReturn(binaryResponseDto); + + Batch response = service.send(sendSmsBatchBinaryRequest); + + TestHelpers.recursiveEquals(response, batchBinary); + } + + @Test + void sendMedia() throws ApiException { + + when(api.send(sendSmsBatchMediaRequest)).thenReturn(mediaResponseDto); + + Batch response = service.send(sendSmsBatchMediaRequest); + + TestHelpers.recursiveEquals(response, batchMedia); + } + + @Test + void sendText() throws ApiException { + + when(api.send(sendSmsBatchTextRequest)).thenReturn(textResponseDto); + + Batch response = service.send(sendSmsBatchTextRequest); + + TestHelpers.recursiveEquals(response, batchText); + } + + @Test + void dryRun() throws ApiException { + + when(api.dryRun(eq(true), eq(456), eq(sendSmsBatchTextRequest))).thenReturn(dryRunResponseDto); + + DryRunResponse response = service.dryRun(true, 456, sendSmsBatchTextRequest); + + TestHelpers.recursiveEquals(response, dryRunResponseDto); + } + + @Test + void list() throws ApiException { + + when(api.list(eq(null), eq(null), eq(null), eq(null), eq(null), eq(null))) + .thenReturn(listBatchesResponseDtoPage0); + when(api.list(eq(1), eq(null), eq(null), eq(null), eq(null), eq(null))) + .thenReturn(listBatchesResponseDtoPage1); + when(api.list(eq(2), eq(null), eq(null), eq(null), eq(null), eq(null))) + .thenReturn(listBatchesResponseDtoPage2); + ListBatchesResponse response = service.list(null); + + Iterator iterator = response.iterator(); + Batch batch = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TestHelpers.recursiveEquals( + batch, + BatchBinary.builder() + .setId("01HEAWCHESCXG8SDG5R10VF8E1") + .setTo(Collections.singletonList("339876543213")) + .setFrom("33123456789") + .setCanceled(false) + .setBody("the body") + .setCreatedAt(Instant.parse("2023-11-03T15:21:21.113Z")) + .setModifiedAt(Instant.parse("2023-11-03T15:21:21.568Z")) + .setDeliveryReport(DeliveryReportType.NONE) + .setExpireAt(Instant.parse("2023-11-06T15:21:21.973Z")) + .setClientReference("a client reference") + .setFeedbackEnabled(false) + .build()); + + batch = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TestHelpers.recursiveEquals( + batch, + BatchText.builder() + .setId("01HEAC0AG69SVYYQ675VPYT28Q") + .setTo(Collections.singletonList("3300000000")) + .setCanceled(false) + .setBody("the body") + .setCreatedAt(Instant.parse("2023-11-03T10:35:03.558Z")) + .setModifiedAt(Instant.parse("2023-11-03T10:35:03.666Z")) + .setDeliveryReport(DeliveryReportType.NONE) + .setExpireAt(Instant.parse("2023-11-03T10:35:03.558Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build()); + + batch = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + TestHelpers.recursiveEquals( + batch, + BatchMedia.builder() + .setId("01HEABZ9S80D4ENE3X6CPMATZR") + .setTo(Collections.singletonList("331111111")) + .setCanceled(false) + .setBody(MediaBody.builder().setUrl("an URL").build()) + .setCreatedAt(Instant.parse("2023-11-03T10:34:30.056Z")) + .setModifiedAt(Instant.parse("2023-11-03T10:34:30.156Z")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setExpireAt(Instant.parse("2023-11-06T10:34:30.256Z")) + .setFeedbackEnabled(false) + .build()); + } + + @Test + void updateText() throws ApiException { + + when(api.update(eq("foo text batch id"), eq(updateSmsBatchTextRequest))) + .thenReturn(textResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchTextRequest); + + TestHelpers.recursiveEquals(response, batchText); + } + + @Test + void updateMedia() throws ApiException { + + when(api.update(eq("foo text batch id"), eq(updateSmsBatchMediaRequest))) + .thenReturn(mediaResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchMediaRequest); + + TestHelpers.recursiveEquals(response, batchMedia); + } + + @Test + void updateBinary() throws ApiException { + + when(api.update(eq("foo text batch id"), eq(updateSmsBatchBinaryRequest))) + .thenReturn(binaryResponseDto); + + Batch response = service.update("foo text batch id", updateSmsBatchBinaryRequest); + + TestHelpers.recursiveEquals(response, batchBinary); + } + + @Test + void replaceBinary() throws ApiException { + + when(api.replace(eq("foo text batch id"), eq(sendSmsBatchBinaryRequest))) + .thenReturn(binaryResponseDto); + + Batch response = service.replace("foo text batch id", sendSmsBatchBinaryRequest); + + TestHelpers.recursiveEquals(response, batchBinary); + } + + @Test + void replaceMedia() throws ApiException { + + when(api.replace(eq("foo text batch id"), eq(sendSmsBatchMediaRequest))) + .thenReturn(mediaResponseDto); + + Batch response = service.replace("foo text batch id", sendSmsBatchMediaRequest); + + TestHelpers.recursiveEquals(response, batchMedia); + } + + @Test + void replaceText() throws ApiException { + + when(api.replace(eq("foo text batch id"), eq(sendSmsBatchTextRequest))) + .thenReturn(textResponseDto); + + Batch response = service.replace("foo text batch id", sendSmsBatchTextRequest); + + TestHelpers.recursiveEquals(response, batchText); + } + + @Test + void cancelBatch() throws ApiException { + + when(api.cancel(eq("foo text batch id"))).thenReturn(textResponseDto); + + Batch response = service.cancel("foo text batch id"); + + TestHelpers.recursiveEquals(response, batchText); + } + + @Test + void sendDeliveryFeedback() throws ApiException { + SendDeliveryFeedbackRequest request = + SendDeliveryFeedbackRequest.builder().setRecipients(Arrays.asList("foo", "foo2")).build(); + + service.sendDeliveryFeedback("foo text batch id", request); + + verify(api).sendDeliveryFeedback(eq("foo text batch id"), recipientsCaptor.capture()); + + SendDeliveryFeedbackRequest dto = recipientsCaptor.getValue(); + TestHelpers.recursiveEquals(dto, request); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java new file mode 100644 index 000000000..c09a23306 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java @@ -0,0 +1,83 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.models.SmsContext; +import com.sinch.sdk.models.UnifiedCredentials; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +class SMSServiceTest { + + @Mock HttpClient httpClient; + + @Test + void doNotAcceptNullKey() { + UnifiedCredentials credentials = + UnifiedCredentials.builder().setKeyId(null).setKeySecret("foo").setProjectId("foo").build(); + SmsContext context = SmsContext.builder().build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new SMSService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("keyId")); + } + + @Test + void doNotAcceptNullKeySecret() { + UnifiedCredentials credentials = + UnifiedCredentials.builder().setKeyId("foo").setKeySecret(null).setProjectId("foo").build(); + SmsContext context = SmsContext.builder().build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new SMSService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("keySecret")); + } + + @Test + void doNotAcceptNullProject() { + UnifiedCredentials credentials = + UnifiedCredentials.builder().setKeyId("foo").setKeySecret("foo").setProjectId(null).build(); + SmsContext context = SmsContext.builder().build(); + ServerConfiguration server = new ServerConfiguration(""); + + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new SMSService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("projectId")); + } + + @Test + void doNotAcceptNullCredentials() { + + SmsContext context = SmsContext.builder().build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + NullPointerException.class, () -> new SMSService(null, context, server, httpClient)); + assertTrue(exception.getMessage().contains("Credentials must be defined")); + } + + @Test + void doNotAcceptNullContext() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + NullPointerException.class, + () -> new SMSService(credentials, null, server, httpClient)); + assertTrue(exception.getMessage().contains("Context must be defined")); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java new file mode 100644 index 000000000..4db3b56d0 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java @@ -0,0 +1,404 @@ +package com.sinch.sdk.e2e.domains.sms.v1; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchText; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunPerRecipientDetails; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.AbstractMap; +import java.util.Arrays; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.jupiter.api.Assertions; + +public class BatchesSteps { + + BatchesService service; + + Batch sendTextResponse; + Batch sendTextWithParametersResponse; + DryRunResponse dryRunResponse; + ListBatchesResponse listOnePageResponse; + ListBatchesResponse listAllResponse; + ListBatchesResponse listAllByPageResponse; + Batch getBatchResponse; + Batch updateResponse; + Batch replaceResponse; + Batch cancelResponse; + Boolean sendDeliveryFeedbackPassed; + + @Given("^the SMS service \"Batches\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().v1().batches(); + } + + @When("^I send a request to send a text message$") + public void send() { + TextRequest request = + TextRequest.builder() + .setBody("SMS body message") + .setTo(Collections.singletonList("+12017777777")) + .setFrom("+12015555555") + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setFeedbackEnabled(true) + .build(); + + sendTextResponse = service.send(request); + } + + @When("^I send a request to send a text message with multiple parameters$") + public void sendWithParameters() { + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("+12017777777", "John"), + new AbstractMap.SimpleEntry<>("+12018888888", "Paul"), + new AbstractMap.SimpleEntry<>("default", "there")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map codeParameters = + Stream.of(new AbstractMap.SimpleEntry<>("+12017777777", "HALLOWEEN20 \uD83C\uDF83")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("code", codeParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + TextRequest request = + TextRequest.builder() + .setBody("Hello ${name}! Get 20% off with this discount code ${code}") + .setTo(Arrays.asList("+12017777777", "+12018888888")) + .setFrom("+12015555555") + .setParameters(parameters) + .setDeliveryReport(DeliveryReportType.FULL) + .build(); + + sendTextWithParametersResponse = service.send(request); + } + + @When("^I send a request to perform a dry run of a batch$") + public void dryRun() { + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("+12017777777", "John"), + new AbstractMap.SimpleEntry<>("default", "there")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of(new AbstractMap.SimpleEntry<>("name", nameParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + TextRequest request = + TextRequest.builder() + .setBody("Hello ${name}!") + .setTo(Arrays.asList("+12017777777", "+12018888888", "+12019999999")) + .setFrom("+12015555555") + .setParameters(parameters) + .setDeliveryReport(DeliveryReportType.NONE) + .build(); + + dryRunResponse = service.dryRun(true, 3, request); + } + + @When("^I send a request to list the SMS batches$") + public void listOnePage() { + ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the SMS batches$") + public void listAll() { + ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the SMS batches pages$") + public void listAllByPage() { + ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + + listAllByPageResponse = service.list(request); + } + + @When("^I send a request to retrieve an SMS batch$") + public void get() { + + getBatchResponse = service.get("foo"); + } + + @When("^I send a request to update an SMS batch$") + public void update() { + + UpdateTextRequest request = + UpdateTextRequest.builder() + .setFrom("+12016666666") + .setToAdd(Collections.singletonList("01W4FFL35P4NC4K35SMSGROUP1")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .build(); + updateResponse = service.update("foo", request); + } + + @When("^I send a request to replace an SMS batch$") + public void replace() { + + TextRequest request = + TextRequest.builder() + .setFrom("+12016666666") + .setTo(Collections.singletonList("+12018888888")) + .setBody("This is the replacement batch") + .setSendAt(Instant.parse("2024-06-06T09:35:00Z")) + .build(); + replaceResponse = service.replace("foo", request); + } + + @When("^I send a request to cancel an SMS batch$") + public void cancel() { + + cancelResponse = service.cancel("foo"); + } + + @When("^I send a request to send delivery feedbacks$") + public void sendDeliveryFeedback() { + + SendDeliveryFeedbackRequest request = + SendDeliveryFeedbackRequest.builder() + .setRecipients(Collections.singletonList("+12017777777")) + .build(); + service.sendDeliveryFeedback("foo", request); + sendDeliveryFeedbackPassed = true; + } + + @Then("the response contains the text SMS details") + public void sendResult() { + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Collections.singletonList("12017777777")) + .setFrom("12015555555") + .setCanceled(false) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(sendTextResponse, expected); + } + + @Then("the response contains the text SMS details with multiple parameters") + public void sendWithParametersResult() { + + Map nameParameters = + Stream.of( + new AbstractMap.SimpleEntry<>("+12017777777", "John"), + new AbstractMap.SimpleEntry<>("+12018888888", "Paul"), + new AbstractMap.SimpleEntry<>("default", "there")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map codeParameters = + Stream.of(new AbstractMap.SimpleEntry<>("+12017777777", "HALLOWEEN20 \uD83C\uDF83")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + Map> parameters = + Stream.of( + new AbstractMap.SimpleEntry<>("name", nameParameters), + new AbstractMap.SimpleEntry<>("code", codeParameters)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH2") + .setTo(Arrays.asList("12017777777", "12018888888")) + .setFrom("12015555555") + .setCanceled(false) + .setParameters(parameters) + .setBody("Hello ${name}! Get 20% off with this discount code ${code}") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setExpireAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(sendTextWithParametersResponse, expected); + } + + @Then( + "the response contains the calculated bodies and number of parts for all messages in the" + + " batch") + public void dryRunResult() { + DryRunResponse expected = + DryRunResponse.builder() + .setNumberOfRecipients(3) + .setNumberOfMessages(3) + .setPerRecipient( + Arrays.asList( + DryRunPerRecipientDetails.builder() + .setRecipient("12017777777") + .setNumberOfParts(1) + .setBody("Hello John!") + .setEncoding("text") + .build(), + DryRunPerRecipientDetails.builder() + .setRecipient("12019999999") + .setNumberOfParts(1) + .setBody("Hello there!") + .setEncoding("text") + .build(), + DryRunPerRecipientDetails.builder() + .setRecipient("12018888888") + .setNumberOfParts(1) + .setBody("Hello there!") + .setEncoding("text") + .build())) + .build(); + + TestHelpers.recursiveEquals(dryRunResponse, expected); + } + + @Then("the response contains \"{int}\" SMS batches") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the SMS batches list contains \"{int}\" SMS batches") + public void listAllResult(int expected) { + + ListBatchesResponse response = + null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the SMS batches iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } + + @Then("the response contains the SMS batch details") + public void getResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Collections.singletonList("12017777777")) + .setFrom("12015555555") + .setCanceled(false) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(getBatchResponse, expected); + } + + @Then("the response contains the SMS batch details with updated data") + public void updateResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Arrays.asList("12017777777", "01W4FFL35P4NC4K35SMSGROUP1")) + .setFrom("12016666666") + .setCanceled(false) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:48.054Z")) + .setDeliveryReport(DeliveryReportType.SUMMARY) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(updateResponse, expected); + } + + @Then("the response contains the new SMS batch details with the provided data for replacement") + public void replaceResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Arrays.asList("12018888888")) + .setFrom("12016666666") + .setCanceled(false) + .setBody("This is the replacement batch") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:23:32.504Z")) + .setDeliveryReport(DeliveryReportType.NONE) + .setSendAt(Instant.parse("2024-06-06T09:35:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:35:00Z")) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(replaceResponse, expected); + } + + @Then("the response contains the SMS batch details with a cancelled status") + public void cancelResult() { + + BatchText expected = + BatchText.builder() + .setId("01W4FFL35P4NC4K35SMSBATCH1") + .setTo(Arrays.asList("12017777777")) + .setFrom("12015555555") + .setCanceled(true) + .setBody("SMS body message") + .setCreatedAt(Instant.parse("2024-06-06T09:22:14.304Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:22:29.978Z")) + .setDeliveryReport(DeliveryReportType.FULL) + .setSendAt(Instant.parse("2024-06-06T09:25:00Z")) + .setExpireAt(Instant.parse("2024-06-09T09:25:00Z")) + .setFeedbackEnabled(true) + .setFlashMessage(false) + .build(); + + TestHelpers.recursiveEquals(cancelResponse, expected); + } + + @Then("the delivery feedback response contains no data") + public void setSendDeliveryFeedbackResult() { + Assertions.assertTrue(sendDeliveryFeedbackPassed); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java new file mode 100644 index 000000000..4229a2763 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java @@ -0,0 +1,16 @@ +package com.sinch.sdk.e2e.domains.sms.v1; + +import static io.cucumber.junit.platform.engine.Constants.GLUE_PROPERTY_NAME; + +import org.junit.platform.suite.api.ConfigurationParameter; +import org.junit.platform.suite.api.IncludeEngines; +import org.junit.platform.suite.api.SelectClasspathResource; +import org.junit.platform.suite.api.Suite; +import org.junit.platform.suite.api.SuiteDisplayName; + +@Suite +@SuiteDisplayName("SMS V1") +@IncludeEngines("cucumber") +@SelectClasspathResource("features/sms/batches.feature") +@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v1") +public class SmsIT {} diff --git a/pom.xml b/pom.xml index bb8469c9b..d50d1e596 100644 --- a/pom.xml +++ b/pom.xml @@ -323,6 +323,7 @@ com.sinch.sdk.e2e.domains.conversation.ConversationIT com.sinch.sdk.e2e.domains.sms.v0.SmsIT + com.sinch.sdk.e2e.domains.sms.v1.SmsIT com.sinch.sdk.e2e.domains.voice.v0.VoiceIT com.sinch.sdk.e2e.domains.voice.v1.VoiceIT From 59753f2a606aad5158adbdae4d98a703d1cd8060 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 16 Dec 2024 12:04:48 +0100 Subject: [PATCH 19/65] feat (SMS/Batches): Generated files --- .../sms/api/v1/internal/BatchesApi.java | 800 ++++++++++++++++++ .../models/v1/batches/DeliveryReportType.java | 61 ++ .../sms/models/v1/batches/MediaBody.java | 86 ++ .../sms/models/v1/batches/MediaBodyImpl.java | 145 ++++ .../v1/batches/request/BinaryRequest.java | 281 ++++++ .../v1/batches/request/BinaryRequestImpl.java | 440 ++++++++++ .../v1/batches/request/MediaRequest.java | 263 ++++++ .../v1/batches/request/MediaRequestImpl.java | 413 +++++++++ .../request/SendDeliveryFeedbackRequest.java | 57 ++ .../SendDeliveryFeedbackRequestImpl.java | 91 ++ .../v1/batches/request/TextRequest.java | 332 ++++++++ .../v1/batches/request/TextRequestImpl.java | 531 ++++++++++++ .../batches/request/UpdateBinaryRequest.java | 288 +++++++ .../request/UpdateBinaryRequestImpl.java | 470 ++++++++++ .../batches/request/UpdateMediaRequest.java | 275 ++++++ .../request/UpdateMediaRequestImpl.java | 443 ++++++++++ .../v1/batches/request/UpdateTextRequest.java | 342 ++++++++ .../request/UpdateTextRequestImpl.java | 561 ++++++++++++ .../v1/batches/response/BatchBinary.java | 354 ++++++++ .../v1/batches/response/BatchBinaryImpl.java | 552 ++++++++++++ .../v1/batches/response/BatchMedia.java | 331 ++++++++ .../v1/batches/response/BatchMediaImpl.java | 524 ++++++++++++ .../models/v1/batches/response/BatchText.java | 406 +++++++++ .../v1/batches/response/BatchTextImpl.java | 642 ++++++++++++++ .../response/DryRunPerRecipientDetails.java | 102 +++ .../DryRunPerRecipientDetailsImpl.java | 175 ++++ .../v1/batches/response/DryRunResponse.java | 88 ++ .../batches/response/DryRunResponseImpl.java | 148 ++++ .../response/internal/ApiBatchList.java | 104 +++ .../response/internal/ApiBatchListImpl.java | 176 ++++ .../internal/BatchResponseInternal.java | 16 + .../internal/BatchResponseInternalImpl.java | 400 +++++++++ 32 files changed, 9897 insertions(+) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/DeliveryReportType.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBody.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetails.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetailsImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponse.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternal.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java new file mode 100644 index 000000000..3033d94dc --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java @@ -0,0 +1,800 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1.internal; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.HttpStatus; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +public class BatchesApi { + + private static final Logger LOGGER = Logger.getLogger(BatchesApi.class.getName()); + private HttpClient httpClient; + private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; + private HttpMapper mapper; + + private final String servicePlanId; + + public BatchesApi( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper, + String servicePlanId) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + this.servicePlanId = servicePlanId; + } + + /** + * Cancel a batch message A batch can be canceled at any point. If a batch is canceled while + * it's currently being delivered some messages currently being processed might still be + * delivered. The delivery report will indicate which messages were canceled and which + * weren't. Canceling a batch scheduled in the future will result in an empty delivery report + * while canceling an already sent batch would result in no change to the completed delivery + * report. + * + * @param batchId The batch ID you received from sending a message. (required) + * @return Batch + * @throws ApiException if fails to make API call + */ + public Batch cancel(String batchId) throws ApiException { + + LOGGER.finest( + "[cancel]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "batchId: " + + batchId); + + HttpRequest httpRequest = cancelRequestBuilder(batchId); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest cancelRequestBuilder(String batchId) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling cancel"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException(400, "Missing the required parameter 'batchId' when calling cancel"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.DELETE, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Dry run This operation will perform a dry run of a batch which calculates the bodies and number + * of parts for all messages in the batch without actually sending any messages. + * + * @param perRecipient Whether to include per recipient details in the response (optional) + * @param numberOfRecipients Max number of recipients to include per recipient details for in the + * response (optional, default to 100) + * @param sendRequest (optional) + * @return DryRunResponse + * @throws ApiException if fails to make API call + */ + public DryRunResponse dryRun( + Boolean perRecipient, Integer numberOfRecipients, BatchRequest sendRequest) + throws ApiException { + + LOGGER.finest( + "[dryRun]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "perRecipient: " + + perRecipient + + ", " + + "numberOfRecipients: " + + numberOfRecipients + + ", " + + "sendRequest: " + + sendRequest); + + HttpRequest httpRequest = dryRunRequestBuilder(perRecipient, numberOfRecipients, sendRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest dryRunRequestBuilder( + Boolean perRecipient, Integer numberOfRecipients, BatchRequest sendRequest) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling dryRun"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/dry_run" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != perRecipient) { + localVarQueryParams.add( + new URLParameter( + "per_recipient", + perRecipient, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true)); + } + if (null != numberOfRecipients) { + localVarQueryParams.add( + new URLParameter( + "number_of_recipients", + numberOfRecipients, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true)); + } + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, sendRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Get a batch message This operation returns a specific batch that matches the provided batch ID. + * + * @param batchId The batch ID you received from sending a message. (required) + * @return Batch + * @throws ApiException if fails to make API call + */ + public Batch get(String batchId) throws ApiException { + + LOGGER.finest( + "[get]" + " " + "this.servicePlanId: " + this.servicePlanId + ", " + "batchId: " + batchId); + + HttpRequest httpRequest = getRequestBuilder(batchId); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest getRequestBuilder(String batchId) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling get"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException(400, "Missing the required parameter 'batchId' when calling get"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * List Batches With the list operation you can list batch messages created in the last 14 days + * that you have created. This operation supports pagination. + * + * @param page The page number starting from 0. (optional, default to 0) + * @param pageSize Determines the size of a page. (optional, default to 30) + * @param from Only list messages sent from this sender number. Multiple originating numbers can + * be comma separated. Must be phone numbers or short code. (optional) + * @param startDate Only list messages received at or after this date/time. Formatted as + * [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. + * Default: Now-24 (optional) + * @param endDate Only list messages received before this date/time. Formatted as + * [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. + * (optional) + * @param clientReference Client reference to include (optional) + * @return ApiBatchList + * @throws ApiException if fails to make API call + */ + public ApiBatchList list( + Integer page, + Integer pageSize, + String from, + String startDate, + String endDate, + String clientReference) + throws ApiException { + + LOGGER.finest( + "[list]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "page: " + + page + + ", " + + "pageSize: " + + pageSize + + ", " + + "from: " + + from + + ", " + + "startDate: " + + startDate + + ", " + + "endDate: " + + endDate + + ", " + + "clientReference: " + + clientReference); + + HttpRequest httpRequest = + listRequestBuilder(page, pageSize, from, startDate, endDate, clientReference); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest listRequestBuilder( + Integer page, + Integer pageSize, + String from, + String startDate, + String endDate, + String clientReference) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling list"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != page) { + localVarQueryParams.add( + new URLParameter("page", page, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); + } + if (null != pageSize) { + localVarQueryParams.add( + new URLParameter( + "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); + } + if (null != from) { + localVarQueryParams.add( + new URLParameter("from", from, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); + } + if (null != startDate) { + localVarQueryParams.add( + new URLParameter( + "start_date", startDate, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); + } + if (null != endDate) { + localVarQueryParams.add( + new URLParameter( + "end_date", endDate, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); + } + if (null != clientReference) { + localVarQueryParams.add( + new URLParameter( + "client_reference", + clientReference, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true)); + } + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Replace a batch This operation will replace all the parameters of a batch with the provided + * values. It is the same as cancelling a batch and sending a new one instead. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param sendRequest (optional) + * @return Batch + * @throws ApiException if fails to make API call + */ + public Batch replace(String batchId, BatchRequest sendRequest) throws ApiException { + + LOGGER.finest( + "[replace]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "sendRequest: " + + sendRequest); + + HttpRequest httpRequest = replaceRequestBuilder(batchId, sendRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest replaceRequestBuilder(String batchId, BatchRequest sendRequest) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling replace"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException(400, "Missing the required parameter 'batchId' when calling replace"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, sendRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.PUT, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Send delivery feedback for a message Send feedback if your system can confirm successful + * message delivery. Feedback can only be provided if `feedback_enabled` was set when + * batch was submitted. **Batches**: It is possible to submit feedback multiple times for the same + * batch for different recipients. Feedback without specified recipients is treated as successful + * message delivery to all recipients referenced in the batch. Note that the + * `recipients` key is still required even if the value is empty. **Groups**: If the + * batch message was creating using a group ID, at least one recipient is required. Excluding + * recipients (an empty recipient list) does not work and will result in a failed request. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param sendDeliveryFeedbackRequest A list of phone numbers (MSISDNs) that successfully received + * the message. (required) + * @throws ApiException if fails to make API call + */ + public void sendDeliveryFeedback( + String batchId, SendDeliveryFeedbackRequest sendDeliveryFeedbackRequest) throws ApiException { + + LOGGER.finest( + "[sendDeliveryFeedback]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "sendDeliveryFeedbackRequest: " + + sendDeliveryFeedbackRequest); + + HttpRequest httpRequest = + sendDeliveryFeedbackRequestBuilder(batchId, sendDeliveryFeedbackRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + return; + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest sendDeliveryFeedbackRequestBuilder( + String batchId, SendDeliveryFeedbackRequest sendDeliveryFeedbackRequest) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, + "Missing the required parameter 'this.servicePlanId' when calling sendDeliveryFeedback"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException( + 400, "Missing the required parameter 'batchId' when calling sendDeliveryFeedback"); + } + // verify the required parameter 'sendDeliveryFeedbackRequest' is set + if (sendDeliveryFeedbackRequest == null) { + throw new ApiException( + 400, + "Missing the required parameter 'sendDeliveryFeedbackRequest' when calling" + + " sendDeliveryFeedback"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}/delivery_feedback" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList(); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = + mapper.serialize(localVarContentTypes, sendDeliveryFeedbackRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Send Send a message or a batch of messages. Depending on the length of the body, one message + * might be split into multiple parts and charged accordingly. Any groups targeted in a scheduled + * batch will be evaluated at the time of sending. If a group is deleted between batch creation + * and scheduled date, it will be considered empty. Be sure to use the correct + * [region](/docs/sms/api-reference/#base-url) in the server URL. + * + * @param sendRequest Default schema is Text if type is not specified. (optional) + * @return Batch + * @throws ApiException if fails to make API call + */ + public Batch send(BatchRequest sendRequest) throws ApiException { + + LOGGER.finest( + "[send]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "sendRequest: " + + sendRequest); + + HttpRequest httpRequest = sendRequestBuilder(sendRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest sendRequestBuilder(BatchRequest sendRequest) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling send"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, sendRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Update a Batch message This operation updates all specified parameters of a batch that matches + * the provided batch ID. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param updateBatchRequest (optional) + * @return Batch + * @throws ApiException if fails to make API call + */ + public Batch update(String batchId, UpdateBatchRequest updateBatchRequest) throws ApiException { + + LOGGER.finest( + "[update]" + + " " + + "this.servicePlanId: " + + this.servicePlanId + + ", " + + "batchId: " + + batchId + + ", " + + "updateBatchRequest: " + + updateBatchRequest); + + HttpRequest httpRequest = updateRequestBuilder(batchId, updateBatchRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest updateRequestBuilder(String batchId, UpdateBatchRequest updateBatchRequest) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling update"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException(400, "Missing the required parameter 'batchId' when calling update"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, updateBatchRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/DeliveryReportType.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/DeliveryReportType.java new file mode 100644 index 000000000..e5277bedc --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/DeliveryReportType.java @@ -0,0 +1,61 @@ +package com.sinch.sdk.domains.sms.models.v1.batches; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Kind of delivery report */ +public class DeliveryReportType extends EnumDynamic { + + /** No delivery report callback will be sent. */ + public static final DeliveryReportType NONE = new DeliveryReportType("none"); + + /** A single delivery report callback will be sent. */ + public static final DeliveryReportType SUMMARY = new DeliveryReportType("summary"); + + /** + * A single delivery report callback will be sent which includes a list of recipients per delivery + * status. + */ + public static final DeliveryReportType FULL = new DeliveryReportType("full"); + + /** + * A delivery report callback will be sent for each status change of a message. This could result + * in a lot of callbacks and should be used with caution for larger batches. + * These delivery reports also include a timestamp of when the Delivery Report originated from the + * SMSC. + */ + public static final DeliveryReportType PER_RECIPIENT = new DeliveryReportType("per_recipient"); + + /** + * A delivery report callback representing the final status of a message will be sent for each + * recipient. This will send only one callback per recipient, compared to the multiple callbacks + * sent when using per_recipient. The delivery report will also include a timestamp + * of when it originated from the SMSC. + */ + public static final DeliveryReportType PER_RECIPIENT_FINAL = + new DeliveryReportType("per_recipient_final"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + DeliveryReportType.class, + DeliveryReportType::new, + Arrays.asList(NONE, SUMMARY, FULL, PER_RECIPIENT, PER_RECIPIENT_FINAL)); + + private DeliveryReportType(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static DeliveryReportType from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(DeliveryReportType e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBody.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBody.java new file mode 100644 index 000000000..63c078302 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBody.java @@ -0,0 +1,86 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** The message content, including a URL to the media file */ +@JsonDeserialize(builder = MediaBodyImpl.Builder.class) +public interface MediaBody { + + /** + * The subject text + * + * @return subject + */ + String getSubject(); + + /** + * The message text. Text only media messages will be rejected, please use SMS instead. + * + * @return message + */ + String getMessage(); + + /** + * URL to the media file + * + * @return url + */ + String getUrl(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new MediaBodyImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param subject see getter + * @return Current builder + * @see #getSubject + */ + Builder setSubject(String subject); + + /** + * see getter + * + * @param message see getter + * @return Current builder + * @see #getMessage + */ + Builder setMessage(String message); + + /** + * see getter + * + * @param url see getter + * @return Current builder + * @see #getUrl + */ + Builder setUrl(String url); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + MediaBody build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyImpl.java new file mode 100644 index 000000000..6294d51a1 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/MediaBodyImpl.java @@ -0,0 +1,145 @@ +package com.sinch.sdk.domains.sms.models.v1.batches; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +@JsonPropertyOrder({ + MediaBodyImpl.JSON_PROPERTY_SUBJECT, + MediaBodyImpl.JSON_PROPERTY_MESSAGE, + MediaBodyImpl.JSON_PROPERTY_URL +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class MediaBodyImpl implements MediaBody { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_SUBJECT = "subject"; + + private OptionalValue subject; + + public static final String JSON_PROPERTY_MESSAGE = "message"; + + private OptionalValue message; + + public static final String JSON_PROPERTY_URL = "url"; + + private OptionalValue url; + + public MediaBodyImpl() {} + + protected MediaBodyImpl( + OptionalValue subject, OptionalValue message, OptionalValue url) { + this.subject = subject; + this.message = message; + this.url = url; + } + + @JsonIgnore + public String getSubject() { + return subject.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SUBJECT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue subject() { + return subject; + } + + @JsonIgnore + public String getMessage() { + return message.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue message() { + return message; + } + + @JsonIgnore + public String getUrl() { + return url.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_URL) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue url() { + return url; + } + + /** Return true if this MediaBody object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MediaBodyImpl mediaBody = (MediaBodyImpl) o; + return Objects.equals(this.subject, mediaBody.subject) + && Objects.equals(this.message, mediaBody.message) + && Objects.equals(this.url, mediaBody.url); + } + + @Override + public int hashCode() { + return Objects.hash(subject, message, url); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MediaBodyImpl {\n"); + sb.append(" subject: ").append(toIndentedString(subject)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append(" url: ").append(toIndentedString(url)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements MediaBody.Builder { + OptionalValue subject = OptionalValue.empty(); + OptionalValue message = OptionalValue.empty(); + OptionalValue url = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_SUBJECT) + public Builder setSubject(String subject) { + this.subject = OptionalValue.of(subject); + return this; + } + + @JsonProperty(JSON_PROPERTY_MESSAGE) + public Builder setMessage(String message) { + this.message = OptionalValue.of(message); + return this; + } + + @JsonProperty(JSON_PROPERTY_URL) + public Builder setUrl(String url) { + this.url = OptionalValue.of(url); + return this; + } + + public MediaBody build() { + return new MediaBodyImpl(subject, message, url); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequest.java new file mode 100644 index 000000000..0bb00c522 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequest.java @@ -0,0 +1,281 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +/** BinaryRequest */ +@JsonDeserialize(builder = BinaryRequestImpl.Builder.class) +public interface BinaryRequest extends BatchRequest { + + /** + * A list of phone numbers and group IDs that will receive the batch. More info. + * + * @return to + */ + List getTo(); + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic + * Default Originator not configured. + * + * @return from + */ + String getFrom(); + + /** + * The message content Base64 encoded. Max 140 bytes including udh. + * + * @return body + */ + String getBody(); + + /** + * The UDH header of a binary message HEX encoded. Max 140 bytes including the body. + * + * @return udh + */ + String getUdh(); + + /** + * SMS in binary + * format. + */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_BINARY = new TypeEnum("mt_binary"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_BINARY)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set in the future the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately. Formatted + * as ISO-8601. For example: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Must be after + * send_at. Default and max is 3 days after send_at. Formatted as ISO-8601. For example: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Must be a valid URL. Learn how to + * set a default callback URL here. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch. + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * The type of number for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 6 + * + * @return fromTon + */ + Integer getFromTon(); + + /** + * Number Plan Indicator for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 18 + * + * @return fromNpi + */ + Integer getFromNpi(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BinaryRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(List to); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param udh see getter + * @return Current builder + * @see #getUdh + */ + Builder setUdh(String udh); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param fromTon see getter + * @return Current builder + * @see #getFromTon + */ + Builder setFromTon(Integer fromTon); + + /** + * see getter + * + * @param fromNpi see getter + * @return Current builder + * @see #getFromNpi + */ + Builder setFromNpi(Integer fromNpi); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BinaryRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequestImpl.java new file mode 100644 index 000000000..39fa49dd7 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BinaryRequestImpl.java @@ -0,0 +1,440 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + BinaryRequestImpl.JSON_PROPERTY_TO, + BinaryRequestImpl.JSON_PROPERTY_FROM, + BinaryRequestImpl.JSON_PROPERTY_BODY, + BinaryRequestImpl.JSON_PROPERTY_UDH, + BinaryRequestImpl.JSON_PROPERTY_TYPE, + BinaryRequestImpl.JSON_PROPERTY_DELIVERY_REPORT, + BinaryRequestImpl.JSON_PROPERTY_SEND_AT, + BinaryRequestImpl.JSON_PROPERTY_EXPIRE_AT, + BinaryRequestImpl.JSON_PROPERTY_CALLBACK_URL, + BinaryRequestImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BinaryRequestImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + BinaryRequestImpl.JSON_PROPERTY_FROM_TON, + BinaryRequestImpl.JSON_PROPERTY_FROM_NPI +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BinaryRequestImpl implements BinaryRequest, BatchRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue> to; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_UDH = "udh"; + + private OptionalValue udh; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_FROM_TON = "from_ton"; + + private OptionalValue fromTon; + + public static final String JSON_PROPERTY_FROM_NPI = "from_npi"; + + private OptionalValue fromNpi; + + public BinaryRequestImpl() {} + + protected BinaryRequestImpl( + OptionalValue> to, + OptionalValue from, + OptionalValue body, + OptionalValue udh, + OptionalValue type, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue fromTon, + OptionalValue fromNpi) { + this.to = to; + this.from = from; + this.body = body; + this.udh = udh; + this.type = type; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + } + + @JsonIgnore + public List getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> to() { + return to; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public String getUdh() { + return udh.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UDH) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue udh() { + return udh; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Integer getFromTon() { + return fromTon.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromTon() { + return fromTon; + } + + @JsonIgnore + public Integer getFromNpi() { + return fromNpi.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromNpi() { + return fromNpi; + } + + /** Return true if this BinaryRequest object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BinaryRequestImpl binaryRequest = (BinaryRequestImpl) o; + return Objects.equals(this.to, binaryRequest.to) + && Objects.equals(this.from, binaryRequest.from) + && Objects.equals(this.body, binaryRequest.body) + && Objects.equals(this.udh, binaryRequest.udh) + && Objects.equals(this.type, binaryRequest.type) + && Objects.equals(this.deliveryReport, binaryRequest.deliveryReport) + && Objects.equals(this.sendAt, binaryRequest.sendAt) + && Objects.equals(this.expireAt, binaryRequest.expireAt) + && Objects.equals(this.callbackUrl, binaryRequest.callbackUrl) + && Objects.equals(this.clientReference, binaryRequest.clientReference) + && Objects.equals(this.feedbackEnabled, binaryRequest.feedbackEnabled) + && Objects.equals(this.fromTon, binaryRequest.fromTon) + && Objects.equals(this.fromNpi, binaryRequest.fromNpi); + } + + @Override + public int hashCode() { + return Objects.hash( + to, + from, + body, + udh, + type, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + fromTon, + fromNpi); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BinaryRequestImpl {\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" udh: ").append(toIndentedString(udh)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" fromTon: ").append(toIndentedString(fromTon)).append("\n"); + sb.append(" fromNpi: ").append(toIndentedString(fromNpi)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BinaryRequest.Builder { + OptionalValue> to = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue udh = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_BINARY); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue fromTon = OptionalValue.empty(); + OptionalValue fromNpi = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(List to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_UDH) + public Builder setUdh(String udh) { + this.udh = OptionalValue.of(udh); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + public Builder setFromTon(Integer fromTon) { + this.fromTon = OptionalValue.of(fromTon); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = OptionalValue.of(fromNpi); + return this; + } + + public BinaryRequest build() { + return new BinaryRequestImpl( + to, + from, + body, + udh, + type, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + fromTon, + fromNpi); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequest.java new file mode 100644 index 000000000..1774aad95 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequest.java @@ -0,0 +1,263 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** Only available in the US. Contact your account manager if you wish to send MMS. */ +@JsonDeserialize(builder = MediaRequestImpl.Builder.class) +public interface MediaRequest extends BatchRequest { + + /** + * List of Phone numbers and group IDs that will receive the batch. More info + * + * @return to + */ + List getTo(); + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic + * Default Originator not configured. + * + * @return from + */ + String getFrom(); + + /** + * Get body + * + * @return body + */ + MediaBody getBody(); + + /** + * Contains the parameters that will be used for customizing the message for each recipient. Click here to learn more about + * parameterization. + * + * @return parameters + */ + Map> getParameters(); + + /** MMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_MEDIA = new TypeEnum("mt_media"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_MEDIA)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Must be after + * send_at. Default and max is 3 days after send_at. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Must be valid URL. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * Whether or not you want the media included in your message to be checked against Sinch MMS channel best practices. If set to true, your + * message will be rejected if it doesn't conform to the listed recommendations, otherwise no + * validation will be performed. + * + * @return strictValidation + */ + Boolean getStrictValidation(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new MediaRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(List to); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(MediaBody body); + + /** + * see getter + * + * @param parameters see getter + * @return Current builder + * @see #getParameters + */ + Builder setParameters(Map> parameters); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param strictValidation see getter + * @return Current builder + * @see #getStrictValidation + */ + Builder setStrictValidation(Boolean strictValidation); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + MediaRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequestImpl.java new file mode 100644 index 000000000..227379256 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/MediaRequestImpl.java @@ -0,0 +1,413 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + MediaRequestImpl.JSON_PROPERTY_TO, + MediaRequestImpl.JSON_PROPERTY_FROM, + MediaRequestImpl.JSON_PROPERTY_BODY, + MediaRequestImpl.JSON_PROPERTY_PARAMETERS, + MediaRequestImpl.JSON_PROPERTY_TYPE, + MediaRequestImpl.JSON_PROPERTY_DELIVERY_REPORT, + MediaRequestImpl.JSON_PROPERTY_SEND_AT, + MediaRequestImpl.JSON_PROPERTY_EXPIRE_AT, + MediaRequestImpl.JSON_PROPERTY_CALLBACK_URL, + MediaRequestImpl.JSON_PROPERTY_CLIENT_REFERENCE, + MediaRequestImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + MediaRequestImpl.JSON_PROPERTY_STRICT_VALIDATION +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class MediaRequestImpl implements MediaRequest, BatchRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue> to; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_PARAMETERS = "parameters"; + + private OptionalValue>> parameters; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_STRICT_VALIDATION = "strict_validation"; + + private OptionalValue strictValidation; + + public MediaRequestImpl() {} + + protected MediaRequestImpl( + OptionalValue> to, + OptionalValue from, + OptionalValue body, + OptionalValue>> parameters, + OptionalValue type, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue strictValidation) { + this.to = to; + this.from = from; + this.body = body; + this.parameters = parameters; + this.type = type; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.strictValidation = strictValidation; + } + + @JsonIgnore + public List getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> to() { + return to; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public MediaBody getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public Map> getParameters() { + return parameters.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue>> parameters() { + return parameters; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Boolean getStrictValidation() { + return strictValidation.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STRICT_VALIDATION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue strictValidation() { + return strictValidation; + } + + /** Return true if this MediaRequest object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MediaRequestImpl mediaRequest = (MediaRequestImpl) o; + return Objects.equals(this.to, mediaRequest.to) + && Objects.equals(this.from, mediaRequest.from) + && Objects.equals(this.body, mediaRequest.body) + && Objects.equals(this.parameters, mediaRequest.parameters) + && Objects.equals(this.type, mediaRequest.type) + && Objects.equals(this.deliveryReport, mediaRequest.deliveryReport) + && Objects.equals(this.sendAt, mediaRequest.sendAt) + && Objects.equals(this.expireAt, mediaRequest.expireAt) + && Objects.equals(this.callbackUrl, mediaRequest.callbackUrl) + && Objects.equals(this.clientReference, mediaRequest.clientReference) + && Objects.equals(this.feedbackEnabled, mediaRequest.feedbackEnabled) + && Objects.equals(this.strictValidation, mediaRequest.strictValidation); + } + + @Override + public int hashCode() { + return Objects.hash( + to, + from, + body, + parameters, + type, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + strictValidation); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MediaRequestImpl {\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" strictValidation: ").append(toIndentedString(strictValidation)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements MediaRequest.Builder { + OptionalValue> to = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue>> parameters = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_MEDIA); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue strictValidation = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(List to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(MediaBody body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + public Builder setParameters(Map> parameters) { + this.parameters = OptionalValue.of(parameters); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_STRICT_VALIDATION) + public Builder setStrictValidation(Boolean strictValidation) { + this.strictValidation = OptionalValue.of(strictValidation); + return this; + } + + public MediaRequest build() { + return new MediaRequestImpl( + to, + from, + body, + parameters, + type, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + strictValidation); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequest.java new file mode 100644 index 000000000..809c98a80 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequest.java @@ -0,0 +1,57 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; + +/** SendDeliveryFeedbackRequest */ +@JsonDeserialize(builder = SendDeliveryFeedbackRequestImpl.Builder.class) +public interface SendDeliveryFeedbackRequest { + + /** + * A list of phone numbers (MSISDNs) that have successfully received the message. The key is + * required, however, the value can be an empty array ([]) for a batch. If + * the feedback was enabled for a group, at least one phone number is required. + * + * @return recipients + */ + List getRecipients(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new SendDeliveryFeedbackRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param recipients see getter + * @return Current builder + * @see #getRecipients + */ + Builder setRecipients(List recipients); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + SendDeliveryFeedbackRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestImpl.java new file mode 100644 index 000000000..e9db52653 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestImpl.java @@ -0,0 +1,91 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({SendDeliveryFeedbackRequestImpl.JSON_PROPERTY_RECIPIENTS}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class SendDeliveryFeedbackRequestImpl implements SendDeliveryFeedbackRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_RECIPIENTS = "recipients"; + + private OptionalValue> recipients; + + public SendDeliveryFeedbackRequestImpl() {} + + protected SendDeliveryFeedbackRequestImpl(OptionalValue> recipients) { + this.recipients = recipients; + } + + @JsonIgnore + public List getRecipients() { + return recipients.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECIPIENTS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> recipients() { + return recipients; + } + + /** Return true if this ApiDeliveryFeedback object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + SendDeliveryFeedbackRequestImpl apiDeliveryFeedback = (SendDeliveryFeedbackRequestImpl) o; + return Objects.equals(this.recipients, apiDeliveryFeedback.recipients); + } + + @Override + public int hashCode() { + return Objects.hash(recipients); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SendDeliveryFeedbackRequestImpl {\n"); + sb.append(" recipients: ").append(toIndentedString(recipients)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements SendDeliveryFeedbackRequest.Builder { + OptionalValue> recipients = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_RECIPIENTS) + public Builder setRecipients(List recipients) { + this.recipients = OptionalValue.of(recipients); + return this; + } + + public SendDeliveryFeedbackRequest build() { + return new SendDeliveryFeedbackRequestImpl(recipients); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequest.java new file mode 100644 index 000000000..207d0746a --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequest.java @@ -0,0 +1,332 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** TextRequest */ +@JsonDeserialize(builder = TextRequestImpl.Builder.class) +public interface TextRequest extends BatchRequest { + + /** + * List of Phone numbers and group IDs that will receive the batch. More info + * + * @return to + */ + List getTo(); + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic + * Default Originator not configured. + * + * @return from + */ + String getFrom(); + + /** + * Contains the parameters that will be used for customizing the message for each recipient. Click here to learn more about + * parameterization. + * + * @return parameters + */ + Map> getParameters(); + + /** + * The message content + * + * @return body + */ + String getBody(); + + /** Regular SMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_TEXT = new TypeEnum("mt_text"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_TEXT)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Must be after + * send_at. Default and max is 3 days after send_at. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Must be a valid URL. Learn how to + * set a default callback URL here. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * Shows message on screen without user interaction while not saving the message to the inbox. + * + * @return flashMessage + */ + Boolean getFlashMessage(); + + /** + * If set to true the message will be shortened when exceeding one part. + * + * @return truncateConcat + */ + Boolean getTruncateConcat(); + + /** + * Message will be dispatched only if it is not split to more parts than Max Number of Message + * Parts + * + *

minimum: 1 + * + * @return maxNumberOfMessageParts + */ + Integer getMaxNumberOfMessageParts(); + + /** + * The type of number for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 6 + * + * @return fromTon + */ + Integer getFromTon(); + + /** + * Number Plan Indicator for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 18 + * + * @return fromNpi + */ + Integer getFromNpi(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new TextRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(List to); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param parameters see getter + * @return Current builder + * @see #getParameters + */ + Builder setParameters(Map> parameters); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param flashMessage see getter + * @return Current builder + * @see #getFlashMessage + */ + Builder setFlashMessage(Boolean flashMessage); + + /** + * see getter + * + * @param truncateConcat see getter + * @return Current builder + * @see #getTruncateConcat + */ + Builder setTruncateConcat(Boolean truncateConcat); + + /** + * see getter + * + * @param maxNumberOfMessageParts see getter + * @return Current builder + * @see #getMaxNumberOfMessageParts + */ + Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts); + + /** + * see getter + * + * @param fromTon see getter + * @return Current builder + * @see #getFromTon + */ + Builder setFromTon(Integer fromTon); + + /** + * see getter + * + * @param fromNpi see getter + * @return Current builder + * @see #getFromNpi + */ + Builder setFromNpi(Integer fromNpi); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TextRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequestImpl.java new file mode 100644 index 000000000..1cc714f5a --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/TextRequestImpl.java @@ -0,0 +1,531 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + TextRequestImpl.JSON_PROPERTY_TO, + TextRequestImpl.JSON_PROPERTY_FROM, + TextRequestImpl.JSON_PROPERTY_PARAMETERS, + TextRequestImpl.JSON_PROPERTY_BODY, + TextRequestImpl.JSON_PROPERTY_TYPE, + TextRequestImpl.JSON_PROPERTY_DELIVERY_REPORT, + TextRequestImpl.JSON_PROPERTY_SEND_AT, + TextRequestImpl.JSON_PROPERTY_EXPIRE_AT, + TextRequestImpl.JSON_PROPERTY_CALLBACK_URL, + TextRequestImpl.JSON_PROPERTY_CLIENT_REFERENCE, + TextRequestImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + TextRequestImpl.JSON_PROPERTY_FLASH_MESSAGE, + TextRequestImpl.JSON_PROPERTY_TRUNCATE_CONCAT, + TextRequestImpl.JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS, + TextRequestImpl.JSON_PROPERTY_FROM_TON, + TextRequestImpl.JSON_PROPERTY_FROM_NPI +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TextRequestImpl implements TextRequest, BatchRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue> to; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_PARAMETERS = "parameters"; + + private OptionalValue>> parameters; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_FLASH_MESSAGE = "flash_message"; + + private OptionalValue flashMessage; + + public static final String JSON_PROPERTY_TRUNCATE_CONCAT = "truncate_concat"; + + private OptionalValue truncateConcat; + + public static final String JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS = + "max_number_of_message_parts"; + + private OptionalValue maxNumberOfMessageParts; + + public static final String JSON_PROPERTY_FROM_TON = "from_ton"; + + private OptionalValue fromTon; + + public static final String JSON_PROPERTY_FROM_NPI = "from_npi"; + + private OptionalValue fromNpi; + + public TextRequestImpl() {} + + protected TextRequestImpl( + OptionalValue> to, + OptionalValue from, + OptionalValue>> parameters, + OptionalValue body, + OptionalValue type, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue flashMessage, + OptionalValue truncateConcat, + OptionalValue maxNumberOfMessageParts, + OptionalValue fromTon, + OptionalValue fromNpi) { + this.to = to; + this.from = from; + this.parameters = parameters; + this.body = body; + this.type = type; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.flashMessage = flashMessage; + this.truncateConcat = truncateConcat; + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + } + + @JsonIgnore + public List getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> to() { + return to; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public Map> getParameters() { + return parameters.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue>> parameters() { + return parameters; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Boolean getFlashMessage() { + return flashMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FLASH_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue flashMessage() { + return flashMessage; + } + + @JsonIgnore + public Boolean getTruncateConcat() { + return truncateConcat.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TRUNCATE_CONCAT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue truncateConcat() { + return truncateConcat; + } + + @JsonIgnore + public Integer getMaxNumberOfMessageParts() { + return maxNumberOfMessageParts.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue maxNumberOfMessageParts() { + return maxNumberOfMessageParts; + } + + @JsonIgnore + public Integer getFromTon() { + return fromTon.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromTon() { + return fromTon; + } + + @JsonIgnore + public Integer getFromNpi() { + return fromNpi.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromNpi() { + return fromNpi; + } + + /** Return true if this TextRequest object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TextRequestImpl textRequest = (TextRequestImpl) o; + return Objects.equals(this.to, textRequest.to) + && Objects.equals(this.from, textRequest.from) + && Objects.equals(this.parameters, textRequest.parameters) + && Objects.equals(this.body, textRequest.body) + && Objects.equals(this.type, textRequest.type) + && Objects.equals(this.deliveryReport, textRequest.deliveryReport) + && Objects.equals(this.sendAt, textRequest.sendAt) + && Objects.equals(this.expireAt, textRequest.expireAt) + && Objects.equals(this.callbackUrl, textRequest.callbackUrl) + && Objects.equals(this.clientReference, textRequest.clientReference) + && Objects.equals(this.feedbackEnabled, textRequest.feedbackEnabled) + && Objects.equals(this.flashMessage, textRequest.flashMessage) + && Objects.equals(this.truncateConcat, textRequest.truncateConcat) + && Objects.equals(this.maxNumberOfMessageParts, textRequest.maxNumberOfMessageParts) + && Objects.equals(this.fromTon, textRequest.fromTon) + && Objects.equals(this.fromNpi, textRequest.fromNpi); + } + + @Override + public int hashCode() { + return Objects.hash( + to, + from, + parameters, + body, + type, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + flashMessage, + truncateConcat, + maxNumberOfMessageParts, + fromTon, + fromNpi); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TextRequestImpl {\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" flashMessage: ").append(toIndentedString(flashMessage)).append("\n"); + sb.append(" truncateConcat: ").append(toIndentedString(truncateConcat)).append("\n"); + sb.append(" maxNumberOfMessageParts: ") + .append(toIndentedString(maxNumberOfMessageParts)) + .append("\n"); + sb.append(" fromTon: ").append(toIndentedString(fromTon)).append("\n"); + sb.append(" fromNpi: ").append(toIndentedString(fromNpi)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements TextRequest.Builder { + OptionalValue> to = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue>> parameters = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_TEXT); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue flashMessage = OptionalValue.empty(); + OptionalValue truncateConcat = OptionalValue.empty(); + OptionalValue maxNumberOfMessageParts = OptionalValue.empty(); + OptionalValue fromTon = OptionalValue.empty(); + OptionalValue fromNpi = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(List to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + public Builder setParameters(Map> parameters) { + this.parameters = OptionalValue.of(parameters); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_FLASH_MESSAGE) + public Builder setFlashMessage(Boolean flashMessage) { + this.flashMessage = OptionalValue.of(flashMessage); + return this; + } + + @JsonProperty(JSON_PROPERTY_TRUNCATE_CONCAT) + public Builder setTruncateConcat(Boolean truncateConcat) { + this.truncateConcat = OptionalValue.of(truncateConcat); + return this; + } + + @JsonProperty(JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS) + public Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts) { + this.maxNumberOfMessageParts = OptionalValue.of(maxNumberOfMessageParts); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + public Builder setFromTon(Integer fromTon) { + this.fromTon = OptionalValue.of(fromTon); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = OptionalValue.of(fromNpi); + return this; + } + + public TextRequest build() { + return new TextRequestImpl( + to, + from, + parameters, + body, + type, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + flashMessage, + truncateConcat, + maxNumberOfMessageParts, + fromTon, + fromNpi); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java new file mode 100644 index 000000000..e0696bb75 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java @@ -0,0 +1,288 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +/** Update binary message */ +@JsonDeserialize(builder = UpdateBinaryRequestImpl.Builder.class) +public interface UpdateBinaryRequest extends UpdateBatchRequest, BatchRequest { + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. + * + * @return from + */ + String getFrom(); + + /** SMS in binary format */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_BINARY = new TypeEnum("mt_binary"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_BINARY)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * List of phone numbers and group IDs to add to the batch. + * + * @return toAdd + */ + List getToAdd(); + + /** + * List of phone numbers and group IDs to remove from the batch. + * + * @return toRemove + */ + List getToRemove(); + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set, in the future the message will be delayed until send_at occurs. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. Constraints: Must be before expire_at. If set in the past, + * messages will be sent immediately. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Constraints: Must be + * after send_at Default: 3 days after send_at + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Constraints: Must be valid URL. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * The message content Base64 encoded. Max 140 bytes together with udh. + * + * @return body + */ + String getBody(); + + /** + * The UDH header of a binary message HEX encoded. Max 140 bytes together with body. + * + * @return udh + */ + String getUdh(); + + /** + * The type of number for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 6 + * + * @return fromTon + */ + Integer getFromTon(); + + /** + * Number Plan Indicator for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 18 + * + * @return fromNpi + */ + Integer getFromNpi(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new UpdateBinaryRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param toAdd see getter + * @return Current builder + * @see #getToAdd + */ + Builder setToAdd(List toAdd); + + /** + * see getter + * + * @param toRemove see getter + * @return Current builder + * @see #getToRemove + */ + Builder setToRemove(List toRemove); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param udh see getter + * @return Current builder + * @see #getUdh + */ + Builder setUdh(String udh); + + /** + * see getter + * + * @param fromTon see getter + * @return Current builder + * @see #getFromTon + */ + Builder setFromTon(Integer fromTon); + + /** + * see getter + * + * @param fromNpi see getter + * @return Current builder + * @see #getFromNpi + */ + Builder setFromNpi(Integer fromNpi); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + UpdateBinaryRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java new file mode 100644 index 000000000..9e3dc24fc --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java @@ -0,0 +1,470 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + UpdateBinaryRequestImpl.JSON_PROPERTY_FROM, + UpdateBinaryRequestImpl.JSON_PROPERTY_TYPE, + UpdateBinaryRequestImpl.JSON_PROPERTY_TO_ADD, + UpdateBinaryRequestImpl.JSON_PROPERTY_TO_REMOVE, + UpdateBinaryRequestImpl.JSON_PROPERTY_DELIVERY_REPORT, + UpdateBinaryRequestImpl.JSON_PROPERTY_SEND_AT, + UpdateBinaryRequestImpl.JSON_PROPERTY_EXPIRE_AT, + UpdateBinaryRequestImpl.JSON_PROPERTY_CALLBACK_URL, + UpdateBinaryRequestImpl.JSON_PROPERTY_CLIENT_REFERENCE, + UpdateBinaryRequestImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + UpdateBinaryRequestImpl.JSON_PROPERTY_BODY, + UpdateBinaryRequestImpl.JSON_PROPERTY_UDH, + UpdateBinaryRequestImpl.JSON_PROPERTY_FROM_TON, + UpdateBinaryRequestImpl.JSON_PROPERTY_FROM_NPI +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class UpdateBinaryRequestImpl + implements UpdateBinaryRequest, UpdateBatchRequest, BatchRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_TO_ADD = "to_add"; + + private OptionalValue> toAdd; + + public static final String JSON_PROPERTY_TO_REMOVE = "to_remove"; + + private OptionalValue> toRemove; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_UDH = "udh"; + + private OptionalValue udh; + + public static final String JSON_PROPERTY_FROM_TON = "from_ton"; + + private OptionalValue fromTon; + + public static final String JSON_PROPERTY_FROM_NPI = "from_npi"; + + private OptionalValue fromNpi; + + public UpdateBinaryRequestImpl() {} + + protected UpdateBinaryRequestImpl( + OptionalValue from, + OptionalValue type, + OptionalValue> toAdd, + OptionalValue> toRemove, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue body, + OptionalValue udh, + OptionalValue fromTon, + OptionalValue fromNpi) { + this.from = from; + this.type = type; + this.toAdd = toAdd; + this.toRemove = toRemove; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.body = body; + this.udh = udh; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public List getToAdd() { + return toAdd.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> toAdd() { + return toAdd; + } + + @JsonIgnore + public List getToRemove() { + return toRemove.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> toRemove() { + return toRemove; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public String getUdh() { + return udh.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UDH) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue udh() { + return udh; + } + + @JsonIgnore + public Integer getFromTon() { + return fromTon.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromTon() { + return fromTon; + } + + @JsonIgnore + public Integer getFromNpi() { + return fromNpi.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromNpi() { + return fromNpi; + } + + /** Return true if this ApiUpdateBinaryMtMessage object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateBinaryRequestImpl apiUpdateBinaryMtMessage = (UpdateBinaryRequestImpl) o; + return Objects.equals(this.from, apiUpdateBinaryMtMessage.from) + && Objects.equals(this.type, apiUpdateBinaryMtMessage.type) + && Objects.equals(this.toAdd, apiUpdateBinaryMtMessage.toAdd) + && Objects.equals(this.toRemove, apiUpdateBinaryMtMessage.toRemove) + && Objects.equals(this.deliveryReport, apiUpdateBinaryMtMessage.deliveryReport) + && Objects.equals(this.sendAt, apiUpdateBinaryMtMessage.sendAt) + && Objects.equals(this.expireAt, apiUpdateBinaryMtMessage.expireAt) + && Objects.equals(this.callbackUrl, apiUpdateBinaryMtMessage.callbackUrl) + && Objects.equals(this.clientReference, apiUpdateBinaryMtMessage.clientReference) + && Objects.equals(this.feedbackEnabled, apiUpdateBinaryMtMessage.feedbackEnabled) + && Objects.equals(this.body, apiUpdateBinaryMtMessage.body) + && Objects.equals(this.udh, apiUpdateBinaryMtMessage.udh) + && Objects.equals(this.fromTon, apiUpdateBinaryMtMessage.fromTon) + && Objects.equals(this.fromNpi, apiUpdateBinaryMtMessage.fromNpi); + } + + @Override + public int hashCode() { + return Objects.hash( + from, + type, + toAdd, + toRemove, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + body, + udh, + fromTon, + fromNpi); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UpdateBinaryRequestImpl {\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" toAdd: ").append(toIndentedString(toAdd)).append("\n"); + sb.append(" toRemove: ").append(toIndentedString(toRemove)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" udh: ").append(toIndentedString(udh)).append("\n"); + sb.append(" fromTon: ").append(toIndentedString(fromTon)).append("\n"); + sb.append(" fromNpi: ").append(toIndentedString(fromNpi)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements UpdateBinaryRequest.Builder { + OptionalValue from = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_BINARY); + OptionalValue> toAdd = OptionalValue.empty(); + OptionalValue> toRemove = OptionalValue.empty(); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue udh = OptionalValue.empty(); + OptionalValue fromTon = OptionalValue.empty(); + OptionalValue fromNpi = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO_ADD) + public Builder setToAdd(List toAdd) { + this.toAdd = OptionalValue.of(toAdd); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO_REMOVE) + public Builder setToRemove(List toRemove) { + this.toRemove = OptionalValue.of(toRemove); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_UDH) + public Builder setUdh(String udh) { + this.udh = OptionalValue.of(udh); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + public Builder setFromTon(Integer fromTon) { + this.fromTon = OptionalValue.of(fromTon); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = OptionalValue.of(fromNpi); + return this; + } + + public UpdateBinaryRequest build() { + return new UpdateBinaryRequestImpl( + from, + type, + toAdd, + toRemove, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + body, + udh, + fromTon, + fromNpi); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java new file mode 100644 index 000000000..5041cbcf6 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java @@ -0,0 +1,275 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** Update media message */ +@JsonDeserialize(builder = UpdateMediaRequestImpl.Builder.class) +public interface UpdateMediaRequest extends UpdateBatchRequest, BatchRequest { + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. + * + * @return from + */ + String getFrom(); + + /** MMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_MEDIA = new TypeEnum("mt_media"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_MEDIA)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * List of phone numbers and group IDs to add to the batch. + * + * @return toAdd + */ + List getToAdd(); + + /** + * List of phone numbers and group IDs to remove from the batch. + * + * @return toRemove + */ + List getToRemove(); + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set, in the future the message will be delayed until send_at occurs. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. Constraints: Must be before expire_at. If set in the past, + * messages will be sent immediately. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Constraints: Must be + * after send_at Default: 3 days after send_at + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Constraints: Must be valid URL. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * Get body + * + * @return body + */ + MediaBody getBody(); + + /** + * Contains the parameters that will be used for customizing the message for each recipient. Click here to learn more about + * parameterization. + * + * @return parameters + */ + Map> getParameters(); + + /** + * Whether or not you want the media included in your message to be checked against Sinch MMS channel best practices. If set to true, your + * message will be rejected if it doesn't conform to the listed recommendations, otherwise no + * validation will be performed. + * + * @return strictValidation + */ + Boolean getStrictValidation(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new UpdateMediaRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param toAdd see getter + * @return Current builder + * @see #getToAdd + */ + Builder setToAdd(List toAdd); + + /** + * see getter + * + * @param toRemove see getter + * @return Current builder + * @see #getToRemove + */ + Builder setToRemove(List toRemove); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(MediaBody body); + + /** + * see getter + * + * @param parameters see getter + * @return Current builder + * @see #getParameters + */ + Builder setParameters(Map> parameters); + + /** + * see getter + * + * @param strictValidation see getter + * @return Current builder + * @see #getStrictValidation + */ + Builder setStrictValidation(Boolean strictValidation); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + UpdateMediaRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java new file mode 100644 index 000000000..41f6e8743 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java @@ -0,0 +1,443 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + UpdateMediaRequestImpl.JSON_PROPERTY_FROM, + UpdateMediaRequestImpl.JSON_PROPERTY_TYPE, + UpdateMediaRequestImpl.JSON_PROPERTY_TO_ADD, + UpdateMediaRequestImpl.JSON_PROPERTY_TO_REMOVE, + UpdateMediaRequestImpl.JSON_PROPERTY_DELIVERY_REPORT, + UpdateMediaRequestImpl.JSON_PROPERTY_SEND_AT, + UpdateMediaRequestImpl.JSON_PROPERTY_EXPIRE_AT, + UpdateMediaRequestImpl.JSON_PROPERTY_CALLBACK_URL, + UpdateMediaRequestImpl.JSON_PROPERTY_CLIENT_REFERENCE, + UpdateMediaRequestImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + UpdateMediaRequestImpl.JSON_PROPERTY_BODY, + UpdateMediaRequestImpl.JSON_PROPERTY_PARAMETERS, + UpdateMediaRequestImpl.JSON_PROPERTY_STRICT_VALIDATION +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class UpdateMediaRequestImpl + implements UpdateMediaRequest, UpdateBatchRequest, BatchRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_TO_ADD = "to_add"; + + private OptionalValue> toAdd; + + public static final String JSON_PROPERTY_TO_REMOVE = "to_remove"; + + private OptionalValue> toRemove; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_PARAMETERS = "parameters"; + + private OptionalValue>> parameters; + + public static final String JSON_PROPERTY_STRICT_VALIDATION = "strict_validation"; + + private OptionalValue strictValidation; + + public UpdateMediaRequestImpl() {} + + protected UpdateMediaRequestImpl( + OptionalValue from, + OptionalValue type, + OptionalValue> toAdd, + OptionalValue> toRemove, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue body, + OptionalValue>> parameters, + OptionalValue strictValidation) { + this.from = from; + this.type = type; + this.toAdd = toAdd; + this.toRemove = toRemove; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.body = body; + this.parameters = parameters; + this.strictValidation = strictValidation; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public List getToAdd() { + return toAdd.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> toAdd() { + return toAdd; + } + + @JsonIgnore + public List getToRemove() { + return toRemove.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> toRemove() { + return toRemove; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public MediaBody getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public Map> getParameters() { + return parameters.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue>> parameters() { + return parameters; + } + + @JsonIgnore + public Boolean getStrictValidation() { + return strictValidation.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STRICT_VALIDATION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue strictValidation() { + return strictValidation; + } + + /** Return true if this ApiUpdateMmsMtMessage object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateMediaRequestImpl apiUpdateMmsMtMessage = (UpdateMediaRequestImpl) o; + return Objects.equals(this.from, apiUpdateMmsMtMessage.from) + && Objects.equals(this.type, apiUpdateMmsMtMessage.type) + && Objects.equals(this.toAdd, apiUpdateMmsMtMessage.toAdd) + && Objects.equals(this.toRemove, apiUpdateMmsMtMessage.toRemove) + && Objects.equals(this.deliveryReport, apiUpdateMmsMtMessage.deliveryReport) + && Objects.equals(this.sendAt, apiUpdateMmsMtMessage.sendAt) + && Objects.equals(this.expireAt, apiUpdateMmsMtMessage.expireAt) + && Objects.equals(this.callbackUrl, apiUpdateMmsMtMessage.callbackUrl) + && Objects.equals(this.clientReference, apiUpdateMmsMtMessage.clientReference) + && Objects.equals(this.feedbackEnabled, apiUpdateMmsMtMessage.feedbackEnabled) + && Objects.equals(this.body, apiUpdateMmsMtMessage.body) + && Objects.equals(this.parameters, apiUpdateMmsMtMessage.parameters) + && Objects.equals(this.strictValidation, apiUpdateMmsMtMessage.strictValidation); + } + + @Override + public int hashCode() { + return Objects.hash( + from, + type, + toAdd, + toRemove, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + body, + parameters, + strictValidation); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UpdateMediaRequestImpl {\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" toAdd: ").append(toIndentedString(toAdd)).append("\n"); + sb.append(" toRemove: ").append(toIndentedString(toRemove)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" strictValidation: ").append(toIndentedString(strictValidation)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements UpdateMediaRequest.Builder { + OptionalValue from = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_MEDIA); + OptionalValue> toAdd = OptionalValue.empty(); + OptionalValue> toRemove = OptionalValue.empty(); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue>> parameters = OptionalValue.empty(); + OptionalValue strictValidation = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO_ADD) + public Builder setToAdd(List toAdd) { + this.toAdd = OptionalValue.of(toAdd); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO_REMOVE) + public Builder setToRemove(List toRemove) { + this.toRemove = OptionalValue.of(toRemove); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(MediaBody body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + public Builder setParameters(Map> parameters) { + this.parameters = OptionalValue.of(parameters); + return this; + } + + @JsonProperty(JSON_PROPERTY_STRICT_VALIDATION) + public Builder setStrictValidation(Boolean strictValidation) { + this.strictValidation = OptionalValue.of(strictValidation); + return this; + } + + public UpdateMediaRequest build() { + return new UpdateMediaRequestImpl( + from, + type, + toAdd, + toRemove, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + body, + parameters, + strictValidation); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java new file mode 100644 index 000000000..7f7482592 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java @@ -0,0 +1,342 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** Update text message */ +@JsonDeserialize(builder = UpdateTextRequestImpl.Builder.class) +public interface UpdateTextRequest extends UpdateBatchRequest, BatchRequest { + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. + * + * @return from + */ + String getFrom(); + + /** Regular SMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_TEXT = new TypeEnum("mt_text"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_TEXT)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * List of phone numbers and group IDs to add to the batch. + * + * @return toAdd + */ + List getToAdd(); + + /** + * List of phone numbers and group IDs to remove from the batch. + * + * @return toRemove + */ + List getToRemove(); + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set, in the future the message will be delayed until send_at occurs. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. Constraints: Must be before expire_at. If set in the past, + * messages will be sent immediately. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Constraints: Must be + * after send_at Default: 3 days after send_at + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Constraints: Must be valid URL. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * Contains the parameters that will be used for customizing the message for each recipient. Click here to learn more about + * parameterization. + * + * @return parameters + */ + Map> getParameters(); + + /** + * The message content + * + * @return body + */ + String getBody(); + + /** + * The type of number for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 6 + * + * @return fromTon + */ + Integer getFromTon(); + + /** + * Number Plan Indicator for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 18 + * + * @return fromNpi + */ + Integer getFromNpi(); + + /** + * Message will be dispatched only if it is not split to more parts than Max Number of Message + * Parts + * + *

minimum: 1 + * + * @return maxNumberOfMessageParts + */ + Integer getMaxNumberOfMessageParts(); + + /** + * If set to true the message will be shortened when exceeding one part. + * + * @return truncateConcat + */ + Boolean getTruncateConcat(); + + /** + * Shows message on screen without user interaction while not saving the message to the inbox. + * + * @return flashMessage + */ + Boolean getFlashMessage(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new UpdateTextRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param toAdd see getter + * @return Current builder + * @see #getToAdd + */ + Builder setToAdd(List toAdd); + + /** + * see getter + * + * @param toRemove see getter + * @return Current builder + * @see #getToRemove + */ + Builder setToRemove(List toRemove); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param parameters see getter + * @return Current builder + * @see #getParameters + */ + Builder setParameters(Map> parameters); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param fromTon see getter + * @return Current builder + * @see #getFromTon + */ + Builder setFromTon(Integer fromTon); + + /** + * see getter + * + * @param fromNpi see getter + * @return Current builder + * @see #getFromNpi + */ + Builder setFromNpi(Integer fromNpi); + + /** + * see getter + * + * @param maxNumberOfMessageParts see getter + * @return Current builder + * @see #getMaxNumberOfMessageParts + */ + Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts); + + /** + * see getter + * + * @param truncateConcat see getter + * @return Current builder + * @see #getTruncateConcat + */ + Builder setTruncateConcat(Boolean truncateConcat); + + /** + * see getter + * + * @param flashMessage see getter + * @return Current builder + * @see #getFlashMessage + */ + Builder setFlashMessage(Boolean flashMessage); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + UpdateTextRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java new file mode 100644 index 000000000..ece635e2c --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java @@ -0,0 +1,561 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + UpdateTextRequestImpl.JSON_PROPERTY_FROM, + UpdateTextRequestImpl.JSON_PROPERTY_TYPE, + UpdateTextRequestImpl.JSON_PROPERTY_TO_ADD, + UpdateTextRequestImpl.JSON_PROPERTY_TO_REMOVE, + UpdateTextRequestImpl.JSON_PROPERTY_DELIVERY_REPORT, + UpdateTextRequestImpl.JSON_PROPERTY_SEND_AT, + UpdateTextRequestImpl.JSON_PROPERTY_EXPIRE_AT, + UpdateTextRequestImpl.JSON_PROPERTY_CALLBACK_URL, + UpdateTextRequestImpl.JSON_PROPERTY_CLIENT_REFERENCE, + UpdateTextRequestImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + UpdateTextRequestImpl.JSON_PROPERTY_PARAMETERS, + UpdateTextRequestImpl.JSON_PROPERTY_BODY, + UpdateTextRequestImpl.JSON_PROPERTY_FROM_TON, + UpdateTextRequestImpl.JSON_PROPERTY_FROM_NPI, + UpdateTextRequestImpl.JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS, + UpdateTextRequestImpl.JSON_PROPERTY_TRUNCATE_CONCAT, + UpdateTextRequestImpl.JSON_PROPERTY_FLASH_MESSAGE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class UpdateTextRequestImpl implements UpdateTextRequest, UpdateBatchRequest, BatchRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_TO_ADD = "to_add"; + + private OptionalValue> toAdd; + + public static final String JSON_PROPERTY_TO_REMOVE = "to_remove"; + + private OptionalValue> toRemove; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_PARAMETERS = "parameters"; + + private OptionalValue>> parameters; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_FROM_TON = "from_ton"; + + private OptionalValue fromTon; + + public static final String JSON_PROPERTY_FROM_NPI = "from_npi"; + + private OptionalValue fromNpi; + + public static final String JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS = + "max_number_of_message_parts"; + + private OptionalValue maxNumberOfMessageParts; + + public static final String JSON_PROPERTY_TRUNCATE_CONCAT = "truncate_concat"; + + private OptionalValue truncateConcat; + + public static final String JSON_PROPERTY_FLASH_MESSAGE = "flash_message"; + + private OptionalValue flashMessage; + + public UpdateTextRequestImpl() {} + + protected UpdateTextRequestImpl( + OptionalValue from, + OptionalValue type, + OptionalValue> toAdd, + OptionalValue> toRemove, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue>> parameters, + OptionalValue body, + OptionalValue fromTon, + OptionalValue fromNpi, + OptionalValue maxNumberOfMessageParts, + OptionalValue truncateConcat, + OptionalValue flashMessage) { + this.from = from; + this.type = type; + this.toAdd = toAdd; + this.toRemove = toRemove; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.parameters = parameters; + this.body = body; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + this.truncateConcat = truncateConcat; + this.flashMessage = flashMessage; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public List getToAdd() { + return toAdd.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> toAdd() { + return toAdd; + } + + @JsonIgnore + public List getToRemove() { + return toRemove.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> toRemove() { + return toRemove; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Map> getParameters() { + return parameters.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue>> parameters() { + return parameters; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public Integer getFromTon() { + return fromTon.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromTon() { + return fromTon; + } + + @JsonIgnore + public Integer getFromNpi() { + return fromNpi.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromNpi() { + return fromNpi; + } + + @JsonIgnore + public Integer getMaxNumberOfMessageParts() { + return maxNumberOfMessageParts.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue maxNumberOfMessageParts() { + return maxNumberOfMessageParts; + } + + @JsonIgnore + public Boolean getTruncateConcat() { + return truncateConcat.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TRUNCATE_CONCAT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue truncateConcat() { + return truncateConcat; + } + + @JsonIgnore + public Boolean getFlashMessage() { + return flashMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FLASH_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue flashMessage() { + return flashMessage; + } + + /** Return true if this ApiUpdateTextMtMessage object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + UpdateTextRequestImpl apiUpdateTextMtMessage = (UpdateTextRequestImpl) o; + return Objects.equals(this.from, apiUpdateTextMtMessage.from) + && Objects.equals(this.type, apiUpdateTextMtMessage.type) + && Objects.equals(this.toAdd, apiUpdateTextMtMessage.toAdd) + && Objects.equals(this.toRemove, apiUpdateTextMtMessage.toRemove) + && Objects.equals(this.deliveryReport, apiUpdateTextMtMessage.deliveryReport) + && Objects.equals(this.sendAt, apiUpdateTextMtMessage.sendAt) + && Objects.equals(this.expireAt, apiUpdateTextMtMessage.expireAt) + && Objects.equals(this.callbackUrl, apiUpdateTextMtMessage.callbackUrl) + && Objects.equals(this.clientReference, apiUpdateTextMtMessage.clientReference) + && Objects.equals(this.feedbackEnabled, apiUpdateTextMtMessage.feedbackEnabled) + && Objects.equals(this.parameters, apiUpdateTextMtMessage.parameters) + && Objects.equals(this.body, apiUpdateTextMtMessage.body) + && Objects.equals(this.fromTon, apiUpdateTextMtMessage.fromTon) + && Objects.equals(this.fromNpi, apiUpdateTextMtMessage.fromNpi) + && Objects.equals( + this.maxNumberOfMessageParts, apiUpdateTextMtMessage.maxNumberOfMessageParts) + && Objects.equals(this.truncateConcat, apiUpdateTextMtMessage.truncateConcat) + && Objects.equals(this.flashMessage, apiUpdateTextMtMessage.flashMessage); + } + + @Override + public int hashCode() { + return Objects.hash( + from, + type, + toAdd, + toRemove, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + parameters, + body, + fromTon, + fromNpi, + maxNumberOfMessageParts, + truncateConcat, + flashMessage); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class UpdateTextRequestImpl {\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" toAdd: ").append(toIndentedString(toAdd)).append("\n"); + sb.append(" toRemove: ").append(toIndentedString(toRemove)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" fromTon: ").append(toIndentedString(fromTon)).append("\n"); + sb.append(" fromNpi: ").append(toIndentedString(fromNpi)).append("\n"); + sb.append(" maxNumberOfMessageParts: ") + .append(toIndentedString(maxNumberOfMessageParts)) + .append("\n"); + sb.append(" truncateConcat: ").append(toIndentedString(truncateConcat)).append("\n"); + sb.append(" flashMessage: ").append(toIndentedString(flashMessage)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements UpdateTextRequest.Builder { + OptionalValue from = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_TEXT); + OptionalValue> toAdd = OptionalValue.empty(); + OptionalValue> toRemove = OptionalValue.empty(); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue>> parameters = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue fromTon = OptionalValue.empty(); + OptionalValue fromNpi = OptionalValue.empty(); + OptionalValue maxNumberOfMessageParts = OptionalValue.empty(); + OptionalValue truncateConcat = OptionalValue.empty(); + OptionalValue flashMessage = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO_ADD) + public Builder setToAdd(List toAdd) { + this.toAdd = OptionalValue.of(toAdd); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO_REMOVE) + public Builder setToRemove(List toRemove) { + this.toRemove = OptionalValue.of(toRemove); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + public Builder setParameters(Map> parameters) { + this.parameters = OptionalValue.of(parameters); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + public Builder setFromTon(Integer fromTon) { + this.fromTon = OptionalValue.of(fromTon); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = OptionalValue.of(fromNpi); + return this; + } + + @JsonProperty(JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS) + public Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts) { + this.maxNumberOfMessageParts = OptionalValue.of(maxNumberOfMessageParts); + return this; + } + + @JsonProperty(JSON_PROPERTY_TRUNCATE_CONCAT) + public Builder setTruncateConcat(Boolean truncateConcat) { + this.truncateConcat = OptionalValue.of(truncateConcat); + return this; + } + + @JsonProperty(JSON_PROPERTY_FLASH_MESSAGE) + public Builder setFlashMessage(Boolean flashMessage) { + this.flashMessage = OptionalValue.of(flashMessage); + return this; + } + + public UpdateTextRequest build() { + return new UpdateTextRequestImpl( + from, + type, + toAdd, + toRemove, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + parameters, + body, + fromTon, + fromNpi, + maxNumberOfMessageParts, + truncateConcat, + flashMessage); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java new file mode 100644 index 000000000..afeae44af --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java @@ -0,0 +1,354 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +/** BatchBinary */ +@JsonDeserialize(builder = BatchBinaryImpl.Builder.class) +public interface BatchBinary extends Batch { + + /** + * Unique identifier for batch. + * + * @return id + * @readOnly This field is returned by the server and cannot be modified + */ + String getId(); + + /** + * A list of phone numbers and group IDs that have received the batch. More info. + * + * @return to + */ + List getTo(); + + /** + * The sender number provided. Required if the Automatic Default Originator is not configured. + * + * @return from + */ + String getFrom(); + + /** + * Indicates whether or not the batch has been canceled. + * + * @return canceled + * @readOnly This field is returned by the server and cannot be modified + */ + Boolean getCanceled(); + + /** + * The message content provided. Base64 encoded. + * + * @return body + */ + String getBody(); + + /** + * The UDH + * header of a binary message HEX encoded. Max 140 bytes including the body. + * + * @return udh + */ + String getUdh(); + + /** + * SMS in binary + * format. + */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_BINARY = new TypeEnum("mt_binary"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_BINARY)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Timestamp for when batch was created. Formatted as ISO-8601. For example: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return createdAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getCreatedAt(); + + /** + * Timestamp for when batch was last updated. Formatted as ISO-8601. For example: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return modifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getModifiedAt(); + + /** + * The delivery report callback option selected. Will be either none, summary + * , full, per_recipient, or per_recipient_final. + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set, the date and time the message should be delivered. Formatted as ISO-8601. For example: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the date and time the message will expire. Formatted as ISO-8601. For example: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * The callback URL provided in the request. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The string input to identify this batch message. If set, the identifier will be added in the + * delivery report/callback of this batch. + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * The type of number for the sender number. + * + *

minimum: 0 maximum: 6 + * + * @return fromTon + */ + Integer getFromTon(); + + /** + * Number Plan Indicator for the sender number. + * + *

minimum: 0 maximum: 18 + * + * @return fromNpi + */ + Integer getFromNpi(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BatchBinaryImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setId(String id); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(List to); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param canceled see getter + * @return Current builder + * @see #getCanceled + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCanceled(Boolean canceled); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param udh see getter + * @return Current builder + * @see #getUdh + */ + Builder setUdh(String udh); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param modifiedAt see getter + * @return Current builder + * @see #getModifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setModifiedAt(Instant modifiedAt); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param fromTon see getter + * @return Current builder + * @see #getFromTon + */ + Builder setFromTon(Integer fromTon); + + /** + * see getter + * + * @param fromNpi see getter + * @return Current builder + * @see #getFromNpi + */ + Builder setFromNpi(Integer fromNpi); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BatchBinary build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java new file mode 100644 index 000000000..6958afacc --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java @@ -0,0 +1,552 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + BatchBinaryImpl.JSON_PROPERTY_ID, + BatchBinaryImpl.JSON_PROPERTY_TO, + BatchBinaryImpl.JSON_PROPERTY_FROM, + BatchBinaryImpl.JSON_PROPERTY_CANCELED, + BatchBinaryImpl.JSON_PROPERTY_BODY, + BatchBinaryImpl.JSON_PROPERTY_UDH, + BatchBinaryImpl.JSON_PROPERTY_TYPE, + BatchBinaryImpl.JSON_PROPERTY_CREATED_AT, + BatchBinaryImpl.JSON_PROPERTY_MODIFIED_AT, + BatchBinaryImpl.JSON_PROPERTY_DELIVERY_REPORT, + BatchBinaryImpl.JSON_PROPERTY_SEND_AT, + BatchBinaryImpl.JSON_PROPERTY_EXPIRE_AT, + BatchBinaryImpl.JSON_PROPERTY_CALLBACK_URL, + BatchBinaryImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BatchBinaryImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + BatchBinaryImpl.JSON_PROPERTY_FROM_TON, + BatchBinaryImpl.JSON_PROPERTY_FROM_NPI +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BatchBinaryImpl implements BatchBinary, Batch { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue> to; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_CANCELED = "canceled"; + + private OptionalValue canceled; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_UDH = "udh"; + + private OptionalValue udh; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_CREATED_AT = "created_at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_MODIFIED_AT = "modified_at"; + + private OptionalValue modifiedAt; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_FROM_TON = "from_ton"; + + private OptionalValue fromTon; + + public static final String JSON_PROPERTY_FROM_NPI = "from_npi"; + + private OptionalValue fromNpi; + + public BatchBinaryImpl() {} + + protected BatchBinaryImpl( + OptionalValue id, + OptionalValue> to, + OptionalValue from, + OptionalValue canceled, + OptionalValue body, + OptionalValue udh, + OptionalValue type, + OptionalValue createdAt, + OptionalValue modifiedAt, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue fromTon, + OptionalValue fromNpi) { + this.id = id; + this.to = to; + this.from = from; + this.canceled = canceled; + this.body = body; + this.udh = udh; + this.type = type; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonIgnore + public OptionalValue id() { + return id; + } + + @JsonIgnore + public List getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> to() { + return to; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public Boolean getCanceled() { + return canceled.orElse(null); + } + + @JsonIgnore + public OptionalValue canceled() { + return canceled; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public String getUdh() { + return udh.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UDH) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue udh() { + return udh; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue type() { + return type; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonIgnore + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public Instant getModifiedAt() { + return modifiedAt.orElse(null); + } + + @JsonIgnore + public OptionalValue modifiedAt() { + return modifiedAt; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Integer getFromTon() { + return fromTon.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromTon() { + return fromTon; + } + + @JsonIgnore + public Integer getFromNpi() { + return fromNpi.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromNpi() { + return fromNpi; + } + + /** Return true if this BinaryResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BatchBinaryImpl binaryResponse = (BatchBinaryImpl) o; + return Objects.equals(this.id, binaryResponse.id) + && Objects.equals(this.to, binaryResponse.to) + && Objects.equals(this.from, binaryResponse.from) + && Objects.equals(this.canceled, binaryResponse.canceled) + && Objects.equals(this.body, binaryResponse.body) + && Objects.equals(this.udh, binaryResponse.udh) + && Objects.equals(this.type, binaryResponse.type) + && Objects.equals(this.createdAt, binaryResponse.createdAt) + && Objects.equals(this.modifiedAt, binaryResponse.modifiedAt) + && Objects.equals(this.deliveryReport, binaryResponse.deliveryReport) + && Objects.equals(this.sendAt, binaryResponse.sendAt) + && Objects.equals(this.expireAt, binaryResponse.expireAt) + && Objects.equals(this.callbackUrl, binaryResponse.callbackUrl) + && Objects.equals(this.clientReference, binaryResponse.clientReference) + && Objects.equals(this.feedbackEnabled, binaryResponse.feedbackEnabled) + && Objects.equals(this.fromTon, binaryResponse.fromTon) + && Objects.equals(this.fromNpi, binaryResponse.fromNpi); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + to, + from, + canceled, + body, + udh, + type, + createdAt, + modifiedAt, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + fromTon, + fromNpi); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BatchBinaryImpl {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" canceled: ").append(toIndentedString(canceled)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" udh: ").append(toIndentedString(udh)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" modifiedAt: ").append(toIndentedString(modifiedAt)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" fromTon: ").append(toIndentedString(fromTon)).append("\n"); + sb.append(" fromNpi: ").append(toIndentedString(fromNpi)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BatchBinary.Builder { + OptionalValue id = OptionalValue.empty(); + OptionalValue> to = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue canceled = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue udh = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_BINARY); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue modifiedAt = OptionalValue.empty(); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue fromTon = OptionalValue.empty(); + OptionalValue fromNpi = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(List to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_CANCELED) + public Builder setCanceled(Boolean canceled) { + this.canceled = OptionalValue.of(canceled); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_UDH) + public Builder setUdh(String udh) { + this.udh = OptionalValue.of(udh); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATED_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) + public Builder setModifiedAt(Instant modifiedAt) { + this.modifiedAt = OptionalValue.of(modifiedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + public Builder setFromTon(Integer fromTon) { + this.fromTon = OptionalValue.of(fromTon); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = OptionalValue.of(fromNpi); + return this; + } + + public BatchBinary build() { + return new BatchBinaryImpl( + id, + to, + from, + canceled, + body, + udh, + type, + createdAt, + modifiedAt, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + fromTon, + fromNpi); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java new file mode 100644 index 000000000..e00186837 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java @@ -0,0 +1,331 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** BatchMedia */ +@JsonDeserialize(builder = BatchMediaImpl.Builder.class) +public interface BatchMedia extends Batch { + + /** + * Unique identifier for batch + * + * @return id + * @readOnly This field is returned by the server and cannot be modified + */ + String getId(); + + /** + * List of Phone numbers and group IDs that will receive the batch. More info + * + * @return to + */ + List getTo(); + + /** + * Sender number. Required if Automatic Default Originator not configured. + * + * @return from + */ + String getFrom(); + + /** + * Indicates if the batch has been canceled or not. + * + * @return canceled + * @readOnly This field is returned by the server and cannot be modified + */ + Boolean getCanceled(); + + /** + * Get body + * + * @return body + */ + MediaBody getBody(); + + /** + * Contains the parameters that will be used for customizing the message for each recipient. Click here to learn more about + * parameterization. + * + * @return parameters + */ + Map> getParameters(); + + /** Media message */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_MEDIA = new TypeEnum("mt_media"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_MEDIA)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Timestamp for when batch was created. YYYY-MM-DDThh:mm:ss.SSSZ format + * + * @return createdAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getCreatedAt(); + + /** + * Timestamp for when batch was last updated. YYYY-MM-DDThh:mm:ss.SSSZ format + * + * @return modifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getModifiedAt(); + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set in the future the message will be delayed until send_at occurs. Must be before + * expire_at. If set in the past messages will be sent immediately. + * YYYY-MM-DDThh:mm:ss.SSSZ format + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set the system will stop trying to deliver the message at this point. Must be after + * send_at. Default and max is 3 days after send_at. YYYY-MM-DDThh:mm:ss.SSSZ format + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Must be valid URL. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * Whether or not you want the media included in your message to be checked against Sinch MMS channel best practices. If set to true, your + * message will be rejected if it doesn't conform to the listed recommendations, otherwise no + * validation will be performed. + * + * @return strictValidation + */ + Boolean getStrictValidation(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BatchMediaImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setId(String id); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(List to); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param canceled see getter + * @return Current builder + * @see #getCanceled + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCanceled(Boolean canceled); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(MediaBody body); + + /** + * see getter + * + * @param parameters see getter + * @return Current builder + * @see #getParameters + */ + Builder setParameters(Map> parameters); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param modifiedAt see getter + * @return Current builder + * @see #getModifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setModifiedAt(Instant modifiedAt); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param strictValidation see getter + * @return Current builder + * @see #getStrictValidation + */ + Builder setStrictValidation(Boolean strictValidation); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BatchMedia build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java new file mode 100644 index 000000000..4d64ba67c --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java @@ -0,0 +1,524 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + BatchMediaImpl.JSON_PROPERTY_ID, + BatchMediaImpl.JSON_PROPERTY_TO, + BatchMediaImpl.JSON_PROPERTY_FROM, + BatchMediaImpl.JSON_PROPERTY_CANCELED, + BatchMediaImpl.JSON_PROPERTY_BODY, + BatchMediaImpl.JSON_PROPERTY_PARAMETERS, + BatchMediaImpl.JSON_PROPERTY_TYPE, + BatchMediaImpl.JSON_PROPERTY_CREATED_AT, + BatchMediaImpl.JSON_PROPERTY_MODIFIED_AT, + BatchMediaImpl.JSON_PROPERTY_DELIVERY_REPORT, + BatchMediaImpl.JSON_PROPERTY_SEND_AT, + BatchMediaImpl.JSON_PROPERTY_EXPIRE_AT, + BatchMediaImpl.JSON_PROPERTY_CALLBACK_URL, + BatchMediaImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BatchMediaImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + BatchMediaImpl.JSON_PROPERTY_STRICT_VALIDATION +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BatchMediaImpl implements BatchMedia, Batch { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue> to; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_CANCELED = "canceled"; + + private OptionalValue canceled; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_PARAMETERS = "parameters"; + + private OptionalValue>> parameters; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_CREATED_AT = "created_at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_MODIFIED_AT = "modified_at"; + + private OptionalValue modifiedAt; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_STRICT_VALIDATION = "strict_validation"; + + private OptionalValue strictValidation; + + public BatchMediaImpl() {} + + protected BatchMediaImpl( + OptionalValue id, + OptionalValue> to, + OptionalValue from, + OptionalValue canceled, + OptionalValue body, + OptionalValue>> parameters, + OptionalValue type, + OptionalValue createdAt, + OptionalValue modifiedAt, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue strictValidation) { + this.id = id; + this.to = to; + this.from = from; + this.canceled = canceled; + this.body = body; + this.parameters = parameters; + this.type = type; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.strictValidation = strictValidation; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonIgnore + public OptionalValue id() { + return id; + } + + @JsonIgnore + public List getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> to() { + return to; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public Boolean getCanceled() { + return canceled.orElse(null); + } + + @JsonIgnore + public OptionalValue canceled() { + return canceled; + } + + @JsonIgnore + public MediaBody getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public Map> getParameters() { + return parameters.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue>> parameters() { + return parameters; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonIgnore + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public Instant getModifiedAt() { + return modifiedAt.orElse(null); + } + + @JsonIgnore + public OptionalValue modifiedAt() { + return modifiedAt; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Boolean getStrictValidation() { + return strictValidation.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STRICT_VALIDATION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue strictValidation() { + return strictValidation; + } + + /** Return true if this MediaResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BatchMediaImpl mediaResponse = (BatchMediaImpl) o; + return Objects.equals(this.id, mediaResponse.id) + && Objects.equals(this.to, mediaResponse.to) + && Objects.equals(this.from, mediaResponse.from) + && Objects.equals(this.canceled, mediaResponse.canceled) + && Objects.equals(this.body, mediaResponse.body) + && Objects.equals(this.parameters, mediaResponse.parameters) + && Objects.equals(this.type, mediaResponse.type) + && Objects.equals(this.createdAt, mediaResponse.createdAt) + && Objects.equals(this.modifiedAt, mediaResponse.modifiedAt) + && Objects.equals(this.deliveryReport, mediaResponse.deliveryReport) + && Objects.equals(this.sendAt, mediaResponse.sendAt) + && Objects.equals(this.expireAt, mediaResponse.expireAt) + && Objects.equals(this.callbackUrl, mediaResponse.callbackUrl) + && Objects.equals(this.clientReference, mediaResponse.clientReference) + && Objects.equals(this.feedbackEnabled, mediaResponse.feedbackEnabled) + && Objects.equals(this.strictValidation, mediaResponse.strictValidation); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + to, + from, + canceled, + body, + parameters, + type, + createdAt, + modifiedAt, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + strictValidation); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BatchMediaImpl {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" canceled: ").append(toIndentedString(canceled)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" modifiedAt: ").append(toIndentedString(modifiedAt)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" strictValidation: ").append(toIndentedString(strictValidation)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BatchMedia.Builder { + OptionalValue id = OptionalValue.empty(); + OptionalValue> to = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue canceled = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue>> parameters = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_MEDIA); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue modifiedAt = OptionalValue.empty(); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue strictValidation = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(List to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_CANCELED) + public Builder setCanceled(Boolean canceled) { + this.canceled = OptionalValue.of(canceled); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(MediaBody body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + public Builder setParameters(Map> parameters) { + this.parameters = OptionalValue.of(parameters); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATED_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) + public Builder setModifiedAt(Instant modifiedAt) { + this.modifiedAt = OptionalValue.of(modifiedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_STRICT_VALIDATION) + public Builder setStrictValidation(Boolean strictValidation) { + this.strictValidation = OptionalValue.of(strictValidation); + return this; + } + + public BatchMedia build() { + return new BatchMediaImpl( + id, + to, + from, + canceled, + body, + parameters, + type, + createdAt, + modifiedAt, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + strictValidation); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java new file mode 100644 index 000000000..0d4dd2189 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java @@ -0,0 +1,406 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; + +/** BatchText */ +@JsonDeserialize(builder = BatchTextImpl.Builder.class) +public interface BatchText extends Batch { + + /** + * Unique identifier for batch + * + * @return id + * @readOnly This field is returned by the server and cannot be modified + */ + String getId(); + + /** + * List of Phone numbers and group IDs that will receive the batch. More info + * + * @return to + */ + List getTo(); + + /** + * Sender number. Must be valid phone number, short code or alphanumeric. Required if Automatic + * Default Originator not configured. + * + * @return from + */ + String getFrom(); + + /** + * Indicates if the batch has been canceled or not. + * + * @return canceled + * @readOnly This field is returned by the server and cannot be modified + */ + Boolean getCanceled(); + + /** + * Contains the parameters that will be used for customizing the message for each recipient. Click here to learn more about + * parameterization. + * + * @return parameters + */ + Map> getParameters(); + + /** + * The message content + * + * @return body + */ + String getBody(); + + /** Regular SMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MT_TEXT = new TypeEnum("mt_text"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MT_TEXT)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Timestamp for when batch was created. Formatted as ISO-8601:YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return createdAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getCreatedAt(); + + /** + * Timestamp for when batch was last updated. Formatted as ISO-8601:YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return modifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getModifiedAt(); + + /** + * Get deliveryReport + * + * @return deliveryReport + */ + DeliveryReportType getDeliveryReport(); + + /** + * If set in the future, the message will be delayed until send_at occurs. Must be + * before expire_at. If set in the past, messages will be sent immediately. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sendAt + */ + Instant getSendAt(); + + /** + * If set, the system will stop trying to deliver the message at this point. Must be after + * send_at. Default and max is 3 days after send_at. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return expireAt + */ + Instant getExpireAt(); + + /** + * Override the default callback URL for this batch. Must be valid URL. + * + * @return callbackUrl + */ + String getCallbackUrl(); + + /** + * The client identifier of a batch message. If set, the identifier will be added in the delivery + * report/callback of this batch + * + * @return clientReference + */ + String getClientReference(); + + /** + * If set to true, then feedback + * is expected after successful delivery. + * + * @return feedbackEnabled + */ + Boolean getFeedbackEnabled(); + + /** + * Shows message on screen without user interaction while not saving the message to the inbox. + * + * @return flashMessage + */ + Boolean getFlashMessage(); + + /** + * If set to true the message will be shortened when exceeding one part. + * + * @return truncateConcat + */ + Boolean getTruncateConcat(); + + /** + * Message will be dispatched only if it is not split to more parts than Max Number of Message + * Parts + * + *

minimum: 1 + * + * @return maxNumberOfMessageParts + */ + Integer getMaxNumberOfMessageParts(); + + /** + * The type of number for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 6 + * + * @return fromTon + */ + Integer getFromTon(); + + /** + * Number Plan Indicator for the sender number. Use to override the automatic detection. + * + *

minimum: 0 maximum: 18 + * + * @return fromNpi + */ + Integer getFromNpi(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BatchTextImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setId(String id); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(List to); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param canceled see getter + * @return Current builder + * @see #getCanceled + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCanceled(Boolean canceled); + + /** + * see getter + * + * @param parameters see getter + * @return Current builder + * @see #getParameters + */ + Builder setParameters(Map> parameters); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param modifiedAt see getter + * @return Current builder + * @see #getModifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setModifiedAt(Instant modifiedAt); + + /** + * see getter + * + * @param deliveryReport see getter + * @return Current builder + * @see #getDeliveryReport + */ + Builder setDeliveryReport(DeliveryReportType deliveryReport); + + /** + * see getter + * + * @param sendAt see getter + * @return Current builder + * @see #getSendAt + */ + Builder setSendAt(Instant sendAt); + + /** + * see getter + * + * @param expireAt see getter + * @return Current builder + * @see #getExpireAt + */ + Builder setExpireAt(Instant expireAt); + + /** + * see getter + * + * @param callbackUrl see getter + * @return Current builder + * @see #getCallbackUrl + */ + Builder setCallbackUrl(String callbackUrl); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param feedbackEnabled see getter + * @return Current builder + * @see #getFeedbackEnabled + */ + Builder setFeedbackEnabled(Boolean feedbackEnabled); + + /** + * see getter + * + * @param flashMessage see getter + * @return Current builder + * @see #getFlashMessage + */ + Builder setFlashMessage(Boolean flashMessage); + + /** + * see getter + * + * @param truncateConcat see getter + * @return Current builder + * @see #getTruncateConcat + */ + Builder setTruncateConcat(Boolean truncateConcat); + + /** + * see getter + * + * @param maxNumberOfMessageParts see getter + * @return Current builder + * @see #getMaxNumberOfMessageParts + */ + Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts); + + /** + * see getter + * + * @param fromTon see getter + * @return Current builder + * @see #getFromTon + */ + Builder setFromTon(Integer fromTon); + + /** + * see getter + * + * @param fromNpi see getter + * @return Current builder + * @see #getFromNpi + */ + Builder setFromNpi(Integer fromNpi); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BatchText build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java new file mode 100644 index 000000000..2786118d1 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java @@ -0,0 +1,642 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + BatchTextImpl.JSON_PROPERTY_ID, + BatchTextImpl.JSON_PROPERTY_TO, + BatchTextImpl.JSON_PROPERTY_FROM, + BatchTextImpl.JSON_PROPERTY_CANCELED, + BatchTextImpl.JSON_PROPERTY_PARAMETERS, + BatchTextImpl.JSON_PROPERTY_BODY, + BatchTextImpl.JSON_PROPERTY_TYPE, + BatchTextImpl.JSON_PROPERTY_CREATED_AT, + BatchTextImpl.JSON_PROPERTY_MODIFIED_AT, + BatchTextImpl.JSON_PROPERTY_DELIVERY_REPORT, + BatchTextImpl.JSON_PROPERTY_SEND_AT, + BatchTextImpl.JSON_PROPERTY_EXPIRE_AT, + BatchTextImpl.JSON_PROPERTY_CALLBACK_URL, + BatchTextImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BatchTextImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + BatchTextImpl.JSON_PROPERTY_FLASH_MESSAGE, + BatchTextImpl.JSON_PROPERTY_TRUNCATE_CONCAT, + BatchTextImpl.JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS, + BatchTextImpl.JSON_PROPERTY_FROM_TON, + BatchTextImpl.JSON_PROPERTY_FROM_NPI +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BatchTextImpl implements BatchText, Batch { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue> to; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_CANCELED = "canceled"; + + private OptionalValue canceled; + + public static final String JSON_PROPERTY_PARAMETERS = "parameters"; + + private OptionalValue>> parameters; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_CREATED_AT = "created_at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_MODIFIED_AT = "modified_at"; + + private OptionalValue modifiedAt; + + public static final String JSON_PROPERTY_DELIVERY_REPORT = "delivery_report"; + + private OptionalValue deliveryReport; + + public static final String JSON_PROPERTY_SEND_AT = "send_at"; + + private OptionalValue sendAt; + + public static final String JSON_PROPERTY_EXPIRE_AT = "expire_at"; + + private OptionalValue expireAt; + + public static final String JSON_PROPERTY_CALLBACK_URL = "callback_url"; + + private OptionalValue callbackUrl; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FEEDBACK_ENABLED = "feedback_enabled"; + + private OptionalValue feedbackEnabled; + + public static final String JSON_PROPERTY_FLASH_MESSAGE = "flash_message"; + + private OptionalValue flashMessage; + + public static final String JSON_PROPERTY_TRUNCATE_CONCAT = "truncate_concat"; + + private OptionalValue truncateConcat; + + public static final String JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS = + "max_number_of_message_parts"; + + private OptionalValue maxNumberOfMessageParts; + + public static final String JSON_PROPERTY_FROM_TON = "from_ton"; + + private OptionalValue fromTon; + + public static final String JSON_PROPERTY_FROM_NPI = "from_npi"; + + private OptionalValue fromNpi; + + public BatchTextImpl() {} + + protected BatchTextImpl( + OptionalValue id, + OptionalValue> to, + OptionalValue from, + OptionalValue canceled, + OptionalValue>> parameters, + OptionalValue body, + OptionalValue type, + OptionalValue createdAt, + OptionalValue modifiedAt, + OptionalValue deliveryReport, + OptionalValue sendAt, + OptionalValue expireAt, + OptionalValue callbackUrl, + OptionalValue clientReference, + OptionalValue feedbackEnabled, + OptionalValue flashMessage, + OptionalValue truncateConcat, + OptionalValue maxNumberOfMessageParts, + OptionalValue fromTon, + OptionalValue fromNpi) { + this.id = id; + this.to = to; + this.from = from; + this.canceled = canceled; + this.parameters = parameters; + this.body = body; + this.type = type; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.deliveryReport = deliveryReport; + this.sendAt = sendAt; + this.expireAt = expireAt; + this.callbackUrl = callbackUrl; + this.clientReference = clientReference; + this.feedbackEnabled = feedbackEnabled; + this.flashMessage = flashMessage; + this.truncateConcat = truncateConcat; + this.maxNumberOfMessageParts = maxNumberOfMessageParts; + this.fromTon = fromTon; + this.fromNpi = fromNpi; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonIgnore + public OptionalValue id() { + return id; + } + + @JsonIgnore + public List getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> to() { + return to; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public Boolean getCanceled() { + return canceled.orElse(null); + } + + @JsonIgnore + public OptionalValue canceled() { + return canceled; + } + + @JsonIgnore + public Map> getParameters() { + return parameters.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue>> parameters() { + return parameters; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonIgnore + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public Instant getModifiedAt() { + return modifiedAt.orElse(null); + } + + @JsonIgnore + public OptionalValue modifiedAt() { + return modifiedAt; + } + + @JsonIgnore + public DeliveryReportType getDeliveryReport() { + return deliveryReport.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue deliveryReport() { + return deliveryReport; + } + + @JsonIgnore + public Instant getSendAt() { + return sendAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sendAt() { + return sendAt; + } + + @JsonIgnore + public Instant getExpireAt() { + return expireAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue expireAt() { + return expireAt; + } + + @JsonIgnore + public String getCallbackUrl() { + return callbackUrl.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue callbackUrl() { + return callbackUrl; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public Boolean getFeedbackEnabled() { + return feedbackEnabled.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue feedbackEnabled() { + return feedbackEnabled; + } + + @JsonIgnore + public Boolean getFlashMessage() { + return flashMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FLASH_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue flashMessage() { + return flashMessage; + } + + @JsonIgnore + public Boolean getTruncateConcat() { + return truncateConcat.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TRUNCATE_CONCAT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue truncateConcat() { + return truncateConcat; + } + + @JsonIgnore + public Integer getMaxNumberOfMessageParts() { + return maxNumberOfMessageParts.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue maxNumberOfMessageParts() { + return maxNumberOfMessageParts; + } + + @JsonIgnore + public Integer getFromTon() { + return fromTon.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromTon() { + return fromTon; + } + + @JsonIgnore + public Integer getFromNpi() { + return fromNpi.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue fromNpi() { + return fromNpi; + } + + /** Return true if this TextResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BatchTextImpl textResponse = (BatchTextImpl) o; + return Objects.equals(this.id, textResponse.id) + && Objects.equals(this.to, textResponse.to) + && Objects.equals(this.from, textResponse.from) + && Objects.equals(this.canceled, textResponse.canceled) + && Objects.equals(this.parameters, textResponse.parameters) + && Objects.equals(this.body, textResponse.body) + && Objects.equals(this.type, textResponse.type) + && Objects.equals(this.createdAt, textResponse.createdAt) + && Objects.equals(this.modifiedAt, textResponse.modifiedAt) + && Objects.equals(this.deliveryReport, textResponse.deliveryReport) + && Objects.equals(this.sendAt, textResponse.sendAt) + && Objects.equals(this.expireAt, textResponse.expireAt) + && Objects.equals(this.callbackUrl, textResponse.callbackUrl) + && Objects.equals(this.clientReference, textResponse.clientReference) + && Objects.equals(this.feedbackEnabled, textResponse.feedbackEnabled) + && Objects.equals(this.flashMessage, textResponse.flashMessage) + && Objects.equals(this.truncateConcat, textResponse.truncateConcat) + && Objects.equals(this.maxNumberOfMessageParts, textResponse.maxNumberOfMessageParts) + && Objects.equals(this.fromTon, textResponse.fromTon) + && Objects.equals(this.fromNpi, textResponse.fromNpi); + } + + @Override + public int hashCode() { + return Objects.hash( + id, + to, + from, + canceled, + parameters, + body, + type, + createdAt, + modifiedAt, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + flashMessage, + truncateConcat, + maxNumberOfMessageParts, + fromTon, + fromNpi); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BatchTextImpl {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" canceled: ").append(toIndentedString(canceled)).append("\n"); + sb.append(" parameters: ").append(toIndentedString(parameters)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" modifiedAt: ").append(toIndentedString(modifiedAt)).append("\n"); + sb.append(" deliveryReport: ").append(toIndentedString(deliveryReport)).append("\n"); + sb.append(" sendAt: ").append(toIndentedString(sendAt)).append("\n"); + sb.append(" expireAt: ").append(toIndentedString(expireAt)).append("\n"); + sb.append(" callbackUrl: ").append(toIndentedString(callbackUrl)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" feedbackEnabled: ").append(toIndentedString(feedbackEnabled)).append("\n"); + sb.append(" flashMessage: ").append(toIndentedString(flashMessage)).append("\n"); + sb.append(" truncateConcat: ").append(toIndentedString(truncateConcat)).append("\n"); + sb.append(" maxNumberOfMessageParts: ") + .append(toIndentedString(maxNumberOfMessageParts)) + .append("\n"); + sb.append(" fromTon: ").append(toIndentedString(fromTon)).append("\n"); + sb.append(" fromNpi: ").append(toIndentedString(fromNpi)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BatchText.Builder { + OptionalValue id = OptionalValue.empty(); + OptionalValue> to = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue canceled = OptionalValue.empty(); + OptionalValue>> parameters = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MT_TEXT); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue modifiedAt = OptionalValue.empty(); + OptionalValue deliveryReport = OptionalValue.empty(); + OptionalValue sendAt = OptionalValue.empty(); + OptionalValue expireAt = OptionalValue.empty(); + OptionalValue callbackUrl = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue feedbackEnabled = OptionalValue.empty(); + OptionalValue flashMessage = OptionalValue.empty(); + OptionalValue truncateConcat = OptionalValue.empty(); + OptionalValue maxNumberOfMessageParts = OptionalValue.empty(); + OptionalValue fromTon = OptionalValue.empty(); + OptionalValue fromNpi = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(List to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_CANCELED) + public Builder setCanceled(Boolean canceled) { + this.canceled = OptionalValue.of(canceled); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETERS) + public Builder setParameters(Map> parameters) { + this.parameters = OptionalValue.of(parameters); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATED_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) + public Builder setModifiedAt(Instant modifiedAt) { + this.modifiedAt = OptionalValue.of(modifiedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORT) + public Builder setDeliveryReport(DeliveryReportType deliveryReport) { + this.deliveryReport = OptionalValue.of(deliveryReport); + return this; + } + + @JsonProperty(JSON_PROPERTY_SEND_AT) + public Builder setSendAt(Instant sendAt) { + this.sendAt = OptionalValue.of(sendAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_EXPIRE_AT) + public Builder setExpireAt(Instant expireAt) { + this.expireAt = OptionalValue.of(expireAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_CALLBACK_URL) + public Builder setCallbackUrl(String callbackUrl) { + this.callbackUrl = OptionalValue.of(callbackUrl); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FEEDBACK_ENABLED) + public Builder setFeedbackEnabled(Boolean feedbackEnabled) { + this.feedbackEnabled = OptionalValue.of(feedbackEnabled); + return this; + } + + @JsonProperty(JSON_PROPERTY_FLASH_MESSAGE) + public Builder setFlashMessage(Boolean flashMessage) { + this.flashMessage = OptionalValue.of(flashMessage); + return this; + } + + @JsonProperty(JSON_PROPERTY_TRUNCATE_CONCAT) + public Builder setTruncateConcat(Boolean truncateConcat) { + this.truncateConcat = OptionalValue.of(truncateConcat); + return this; + } + + @JsonProperty(JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS) + public Builder setMaxNumberOfMessageParts(Integer maxNumberOfMessageParts) { + this.maxNumberOfMessageParts = OptionalValue.of(maxNumberOfMessageParts); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_TON) + public Builder setFromTon(Integer fromTon) { + this.fromTon = OptionalValue.of(fromTon); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM_NPI) + public Builder setFromNpi(Integer fromNpi) { + this.fromNpi = OptionalValue.of(fromNpi); + return this; + } + + public BatchText build() { + return new BatchTextImpl( + id, + to, + from, + canceled, + parameters, + body, + type, + createdAt, + modifiedAt, + deliveryReport, + sendAt, + expireAt, + callbackUrl, + clientReference, + feedbackEnabled, + flashMessage, + truncateConcat, + maxNumberOfMessageParts, + fromTon, + fromNpi); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetails.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetails.java new file mode 100644 index 000000000..740faac60 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetails.java @@ -0,0 +1,102 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** DryRunPerRecipientDetails */ +@JsonDeserialize(builder = DryRunPerRecipientDetailsImpl.Builder.class) +public interface DryRunPerRecipientDetails { + + /** + * Get recipient + * + * @return recipient + */ + String getRecipient(); + + /** + * Get numberOfParts + * + * @return numberOfParts + */ + Integer getNumberOfParts(); + + /** + * Get body + * + * @return body + */ + String getBody(); + + /** + * Get encoding + * + * @return encoding + */ + String getEncoding(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new DryRunPerRecipientDetailsImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param recipient see getter + * @return Current builder + * @see #getRecipient + */ + Builder setRecipient(String recipient); + + /** + * see getter + * + * @param numberOfParts see getter + * @return Current builder + * @see #getNumberOfParts + */ + Builder setNumberOfParts(Integer numberOfParts); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param encoding see getter + * @return Current builder + * @see #getEncoding + */ + Builder setEncoding(String encoding); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + DryRunPerRecipientDetails build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetailsImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetailsImpl.java new file mode 100644 index 000000000..829005398 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunPerRecipientDetailsImpl.java @@ -0,0 +1,175 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +@JsonPropertyOrder({ + DryRunPerRecipientDetailsImpl.JSON_PROPERTY_RECIPIENT, + DryRunPerRecipientDetailsImpl.JSON_PROPERTY_NUMBER_OF_PARTS, + DryRunPerRecipientDetailsImpl.JSON_PROPERTY_BODY, + DryRunPerRecipientDetailsImpl.JSON_PROPERTY_ENCODING +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class DryRunPerRecipientDetailsImpl implements DryRunPerRecipientDetails { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_RECIPIENT = "recipient"; + + private OptionalValue recipient; + + public static final String JSON_PROPERTY_NUMBER_OF_PARTS = "number_of_parts"; + + private OptionalValue numberOfParts; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_ENCODING = "encoding"; + + private OptionalValue encoding; + + public DryRunPerRecipientDetailsImpl() {} + + protected DryRunPerRecipientDetailsImpl( + OptionalValue recipient, + OptionalValue numberOfParts, + OptionalValue body, + OptionalValue encoding) { + this.recipient = recipient; + this.numberOfParts = numberOfParts; + this.body = body; + this.encoding = encoding; + } + + @JsonIgnore + public String getRecipient() { + return recipient.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECIPIENT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue recipient() { + return recipient; + } + + @JsonIgnore + public Integer getNumberOfParts() { + return numberOfParts.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_PARTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue numberOfParts() { + return numberOfParts; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public String getEncoding() { + return encoding.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ENCODING) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue encoding() { + return encoding; + } + + /** Return true if this DryRunResponse_per_recipient_inner object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DryRunPerRecipientDetailsImpl dryRunResponsePerRecipientInner = + (DryRunPerRecipientDetailsImpl) o; + return Objects.equals(this.recipient, dryRunResponsePerRecipientInner.recipient) + && Objects.equals(this.numberOfParts, dryRunResponsePerRecipientInner.numberOfParts) + && Objects.equals(this.body, dryRunResponsePerRecipientInner.body) + && Objects.equals(this.encoding, dryRunResponsePerRecipientInner.encoding); + } + + @Override + public int hashCode() { + return Objects.hash(recipient, numberOfParts, body, encoding); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DryRunPerRecipientDetailsImpl {\n"); + sb.append(" recipient: ").append(toIndentedString(recipient)).append("\n"); + sb.append(" numberOfParts: ").append(toIndentedString(numberOfParts)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" encoding: ").append(toIndentedString(encoding)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements DryRunPerRecipientDetails.Builder { + OptionalValue recipient = OptionalValue.empty(); + OptionalValue numberOfParts = OptionalValue.empty(); + OptionalValue body = OptionalValue.empty(); + OptionalValue encoding = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_RECIPIENT) + public Builder setRecipient(String recipient) { + this.recipient = OptionalValue.of(recipient); + return this; + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_PARTS) + public Builder setNumberOfParts(Integer numberOfParts) { + this.numberOfParts = OptionalValue.of(numberOfParts); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_ENCODING) + public Builder setEncoding(String encoding) { + this.encoding = OptionalValue.of(encoding); + return this; + } + + public DryRunPerRecipientDetails build() { + return new DryRunPerRecipientDetailsImpl(recipient, numberOfParts, body, encoding); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponse.java new file mode 100644 index 000000000..819875e30 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponse.java @@ -0,0 +1,88 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; + +/** DryRunResponse */ +@JsonDeserialize(builder = DryRunResponseImpl.Builder.class) +public interface DryRunResponse { + + /** + * The number of recipients in the batch + * + * @return numberOfRecipients + */ + Integer getNumberOfRecipients(); + + /** + * The total number of SMS message parts to be sent in the batch + * + * @return numberOfMessages + */ + Integer getNumberOfMessages(); + + /** + * The recipient, the number of message parts to this recipient, the body of the message, and the + * encoding type of each message + * + * @return perRecipient + */ + List getPerRecipient(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new DryRunResponseImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param numberOfRecipients see getter + * @return Current builder + * @see #getNumberOfRecipients + */ + Builder setNumberOfRecipients(Integer numberOfRecipients); + + /** + * see getter + * + * @param numberOfMessages see getter + * @return Current builder + * @see #getNumberOfMessages + */ + Builder setNumberOfMessages(Integer numberOfMessages); + + /** + * see getter + * + * @param perRecipient see getter + * @return Current builder + * @see #getPerRecipient + */ + Builder setPerRecipient(List perRecipient); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + DryRunResponse build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseImpl.java new file mode 100644 index 000000000..eea1b201e --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/DryRunResponseImpl.java @@ -0,0 +1,148 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + DryRunResponseImpl.JSON_PROPERTY_NUMBER_OF_RECIPIENTS, + DryRunResponseImpl.JSON_PROPERTY_NUMBER_OF_MESSAGES, + DryRunResponseImpl.JSON_PROPERTY_PER_RECIPIENT +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class DryRunResponseImpl implements DryRunResponse { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_NUMBER_OF_RECIPIENTS = "number_of_recipients"; + + private OptionalValue numberOfRecipients; + + public static final String JSON_PROPERTY_NUMBER_OF_MESSAGES = "number_of_messages"; + + private OptionalValue numberOfMessages; + + public static final String JSON_PROPERTY_PER_RECIPIENT = "per_recipient"; + + private OptionalValue> perRecipient; + + public DryRunResponseImpl() {} + + protected DryRunResponseImpl( + OptionalValue numberOfRecipients, + OptionalValue numberOfMessages, + OptionalValue> perRecipient) { + this.numberOfRecipients = numberOfRecipients; + this.numberOfMessages = numberOfMessages; + this.perRecipient = perRecipient; + } + + @JsonIgnore + public Integer getNumberOfRecipients() { + return numberOfRecipients.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_RECIPIENTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue numberOfRecipients() { + return numberOfRecipients; + } + + @JsonIgnore + public Integer getNumberOfMessages() { + return numberOfMessages.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_MESSAGES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue numberOfMessages() { + return numberOfMessages; + } + + @JsonIgnore + public List getPerRecipient() { + return perRecipient.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PER_RECIPIENT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> perRecipient() { + return perRecipient; + } + + /** Return true if this DryRunResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DryRunResponseImpl dryRunResponse = (DryRunResponseImpl) o; + return Objects.equals(this.numberOfRecipients, dryRunResponse.numberOfRecipients) + && Objects.equals(this.numberOfMessages, dryRunResponse.numberOfMessages) + && Objects.equals(this.perRecipient, dryRunResponse.perRecipient); + } + + @Override + public int hashCode() { + return Objects.hash(numberOfRecipients, numberOfMessages, perRecipient); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DryRunResponseImpl {\n"); + sb.append(" numberOfRecipients: ").append(toIndentedString(numberOfRecipients)).append("\n"); + sb.append(" numberOfMessages: ").append(toIndentedString(numberOfMessages)).append("\n"); + sb.append(" perRecipient: ").append(toIndentedString(perRecipient)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements DryRunResponse.Builder { + OptionalValue numberOfRecipients = OptionalValue.empty(); + OptionalValue numberOfMessages = OptionalValue.empty(); + OptionalValue> perRecipient = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_RECIPIENTS) + public Builder setNumberOfRecipients(Integer numberOfRecipients) { + this.numberOfRecipients = OptionalValue.of(numberOfRecipients); + return this; + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_MESSAGES) + public Builder setNumberOfMessages(Integer numberOfMessages) { + this.numberOfMessages = OptionalValue.of(numberOfMessages); + return this; + } + + @JsonProperty(JSON_PROPERTY_PER_RECIPIENT) + public Builder setPerRecipient(List perRecipient) { + this.perRecipient = OptionalValue.of(perRecipient); + return this; + } + + public DryRunResponse build() { + return new DryRunResponseImpl(numberOfRecipients, numberOfMessages, perRecipient); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java new file mode 100644 index 000000000..22a925704 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java @@ -0,0 +1,104 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.util.List; + +/** ApiBatchList */ +@JsonDeserialize(builder = ApiBatchListImpl.Builder.class) +public interface ApiBatchList { + + /** + * The total number of entries matching the given filters. + * + * @return count + */ + Long getCount(); + + /** + * The requested page. + * + * @return page + */ + Integer getPage(); + + /** + * The page of batches matching the given filters. + * + * @return batches + */ + List getBatches(); + + /** + * The number of entries returned in this request. + * + * @return pageSize + */ + Integer getPageSize(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ApiBatchListImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param count see getter + * @return Current builder + * @see #getCount + */ + Builder setCount(Long count); + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param batches see getter + * @return Current builder + * @see #getBatches + */ + Builder setBatches(List batches); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ApiBatchList build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java new file mode 100644 index 000000000..43c44549a --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java @@ -0,0 +1,176 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response.internal; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + ApiBatchListImpl.JSON_PROPERTY_COUNT, + ApiBatchListImpl.JSON_PROPERTY_PAGE, + ApiBatchListImpl.JSON_PROPERTY_BATCHES, + ApiBatchListImpl.JSON_PROPERTY_PAGE_SIZE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class ApiBatchListImpl implements ApiBatchList { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_COUNT = "count"; + + private OptionalValue count; + + public static final String JSON_PROPERTY_PAGE = "page"; + + private OptionalValue page; + + public static final String JSON_PROPERTY_BATCHES = "batches"; + + private OptionalValue> batches; + + public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; + + private OptionalValue pageSize; + + public ApiBatchListImpl() {} + + protected ApiBatchListImpl( + OptionalValue count, + OptionalValue page, + OptionalValue> batches, + OptionalValue pageSize) { + this.count = count; + this.page = page; + this.batches = batches; + this.pageSize = pageSize; + } + + @JsonIgnore + public Long getCount() { + return count.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue count() { + return count; + } + + @JsonIgnore + public Integer getPage() { + return page.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue page() { + return page; + } + + @JsonIgnore + public List getBatches() { + return batches.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BATCHES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> batches() { + return batches; + } + + @JsonIgnore + public Integer getPageSize() { + return pageSize.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue pageSize() { + return pageSize; + } + + /** Return true if this ApiBatchList object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ApiBatchListImpl apiBatchList = (ApiBatchListImpl) o; + return Objects.equals(this.count, apiBatchList.count) + && Objects.equals(this.page, apiBatchList.page) + && Objects.equals(this.batches, apiBatchList.batches) + && Objects.equals(this.pageSize, apiBatchList.pageSize); + } + + @Override + public int hashCode() { + return Objects.hash(count, page, batches, pageSize); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiBatchListImpl {\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" batches: ").append(toIndentedString(batches)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements ApiBatchList.Builder { + OptionalValue count = OptionalValue.empty(); + OptionalValue page = OptionalValue.empty(); + OptionalValue> batches = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_COUNT) + public Builder setCount(Long count) { + this.count = OptionalValue.of(count); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE) + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + @JsonProperty(JSON_PROPERTY_BATCHES) + public Builder setBatches(List batches) { + this.batches = OptionalValue.of(batches); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public ApiBatchList build() { + return new ApiBatchListImpl(count, page, batches, pageSize); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternal.java new file mode 100644 index 000000000..c62d5fc04 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternal.java @@ -0,0 +1,16 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.response.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = BatchResponseInternalImpl.BatchResponseInternalImplDeserializer.class) +public interface BatchResponseInternal {} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java new file mode 100644 index 000000000..5d58d1c29 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java @@ -0,0 +1,400 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.response.internal; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.utils.databind.JSONNavigator; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchBinaryImpl; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchMediaImpl; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchTextImpl; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +@JsonDeserialize(using = BatchResponseInternalImpl.BatchResponseInternalImplDeserializer.class) +@JsonSerialize(using = BatchResponseInternalImpl.BatchResponseInternalImplSerializer.class) +public class BatchResponseInternalImpl extends AbstractOpenApiSchema + implements BatchResponseInternal { + private static final Logger log = Logger.getLogger(BatchResponseInternalImpl.class.getName()); + + public static final class BatchResponseInternalImplSerializer + extends StdSerializer { + private static final long serialVersionUID = 1L; + + public BatchResponseInternalImplSerializer(Class t) { + super(t); + } + + public BatchResponseInternalImplSerializer() { + this(null); + } + + @Override + public void serialize( + BatchResponseInternalImpl value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.getActualInstance()); + } + } + + public static final class BatchResponseInternalImplDeserializer + extends StdDeserializer { + + private static final long serialVersionUID = 1L; + + public BatchResponseInternalImplDeserializer() { + this(BatchResponseInternalImpl.class); + } + + public BatchResponseInternalImplDeserializer(Class vc) { + super(vc); + } + + @Override + public BatchResponseInternalImpl deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode tree = jp.readValueAsTree(); + Object deserialized = null; + BatchResponseInternalImpl newBatchResponseInternalImpl = new BatchResponseInternalImpl(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "mt_binary": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchBinaryImpl.class); + newBatchResponseInternalImpl.setActualInstance(deserialized); + return newBatchResponseInternalImpl; + case "mt_media": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchMediaImpl.class); + newBatchResponseInternalImpl.setActualInstance(deserialized); + return newBatchResponseInternalImpl; + case "mt_text": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchTextImpl.class); + newBatchResponseInternalImpl.setActualInstance(deserialized); + return newBatchResponseInternalImpl; + case "BinaryResponse": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchBinaryImpl.class); + newBatchResponseInternalImpl.setActualInstance(deserialized); + return newBatchResponseInternalImpl; + case "MediaResponse": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchMediaImpl.class); + newBatchResponseInternalImpl.setActualInstance(deserialized); + return newBatchResponseInternalImpl; + case "TextResponse": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchTextImpl.class); + newBatchResponseInternalImpl.setActualInstance(deserialized); + return newBatchResponseInternalImpl; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for BatchResponseInternalImpl." + + " Possible values: mt_binary mt_media mt_text BinaryResponse MediaResponse" + + " TextResponse", + discriminatorValue)); + } + + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize BatchBinaryImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchBinaryImpl.class.equals(Integer.class) + || BatchBinaryImpl.class.equals(Long.class) + || BatchBinaryImpl.class.equals(Float.class) + || BatchBinaryImpl.class.equals(Double.class) + || BatchBinaryImpl.class.equals(Boolean.class) + || BatchBinaryImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchBinaryImpl.class.equals(Integer.class) + || BatchBinaryImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchBinaryImpl.class.equals(Float.class) + || BatchBinaryImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchBinaryImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchBinaryImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchBinaryImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchBinaryImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchBinaryImpl'", e); + } + + // deserialize BatchMediaImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchMediaImpl.class.equals(Integer.class) + || BatchMediaImpl.class.equals(Long.class) + || BatchMediaImpl.class.equals(Float.class) + || BatchMediaImpl.class.equals(Double.class) + || BatchMediaImpl.class.equals(Boolean.class) + || BatchMediaImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchMediaImpl.class.equals(Integer.class) + || BatchMediaImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchMediaImpl.class.equals(Float.class) + || BatchMediaImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchMediaImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchMediaImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchMediaImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchMediaImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchMediaImpl'", e); + } + + // deserialize BatchTextImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchTextImpl.class.equals(Integer.class) + || BatchTextImpl.class.equals(Long.class) + || BatchTextImpl.class.equals(Float.class) + || BatchTextImpl.class.equals(Double.class) + || BatchTextImpl.class.equals(Boolean.class) + || BatchTextImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchTextImpl.class.equals(Integer.class) + || BatchTextImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchTextImpl.class.equals(Float.class) + || BatchTextImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchTextImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchTextImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchTextImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchTextImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchTextImpl'", e); + } + + if (match == 1) { + BatchResponseInternalImpl ret = new BatchResponseInternalImpl(); + ret.setActualInstance(deserialized); + return ret; + } + throw new IOException( + String.format( + "Failed deserialization for BatchResponseInternalImpl: %d classes match result," + + " expected 1", + match)); + } + + /** Handle deserialization of the 'null' value. */ + @Override + public BatchResponseInternalImpl getNullValue(DeserializationContext ctxt) + throws JsonMappingException { + throw new JsonMappingException(ctxt.getParser(), "BatchResponseInternalImpl cannot be null"); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap<>(); + + public BatchResponseInternalImpl() { + super("oneOf", Boolean.FALSE); + } + + public BatchResponseInternalImpl(BatchBinaryImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public BatchResponseInternalImpl(BatchMediaImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public BatchResponseInternalImpl(BatchTextImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("BatchBinaryImpl", BatchBinaryImpl.class); + schemas.put("BatchMediaImpl", BatchMediaImpl.class); + schemas.put("BatchTextImpl", BatchTextImpl.class); + JSONNavigator.registerDescendants( + BatchResponseInternalImpl.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("mt_binary", BatchBinaryImpl.class); + mappings.put("mt_media", BatchMediaImpl.class); + mappings.put("mt_text", BatchTextImpl.class); + mappings.put("BinaryResponse", BatchBinaryImpl.class); + mappings.put("MediaResponse", BatchMediaImpl.class); + mappings.put("TextResponse", BatchTextImpl.class); + mappings.put("Batch", BatchResponseInternalImpl.class); + JSONNavigator.registerDiscriminator(BatchResponseInternalImpl.class, "type", mappings); + } + + @Override + public Map> getSchemas() { + return BatchResponseInternalImpl.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check the instance parameter is valid + * against the oneOf child schemas: BatchBinaryImpl, BatchMediaImpl, BatchTextImpl + * + *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a + * composed schema (allOf, anyOf, oneOf). + */ + @Override + public void setActualInstance(Object instance) { + if (JSONNavigator.isInstanceOf(BatchBinaryImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(BatchMediaImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(BatchTextImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException( + "Invalid instance type. Must be BatchBinaryImpl, BatchMediaImpl, BatchTextImpl"); + } + + /** + * Get the actual instance, which can be the following: BatchBinaryImpl, BatchMediaImpl, + * BatchTextImpl + * + * @return The actual instance (BatchBinaryImpl, BatchMediaImpl, BatchTextImpl) + */ + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchBinaryImpl`. If the actual instance is not `BatchBinaryImpl`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `BatchBinaryImpl` + * @throws ClassCastException if the instance is not `BatchBinaryImpl` + */ + public BatchBinaryImpl getBatchBinaryImpl() throws ClassCastException { + return (BatchBinaryImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchMediaImpl`. If the actual instance is not `BatchMediaImpl`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `BatchMediaImpl` + * @throws ClassCastException if the instance is not `BatchMediaImpl` + */ + public BatchMediaImpl getBatchMediaImpl() throws ClassCastException { + return (BatchMediaImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchTextImpl`. If the actual instance is not `BatchTextImpl`, the + * ClassCastException will be thrown. + * + * @return The actual instance of `BatchTextImpl` + * @throws ClassCastException if the instance is not `BatchTextImpl` + */ + public BatchTextImpl getBatchTextImpl() throws ClassCastException { + return (BatchTextImpl) super.getActualInstance(); + } + + public static class Deserializer + extends StdDeserializer { + + public Deserializer() { + this(null); + } + + public Deserializer(Class vc) { + super(vc); + } + + @Override + public com.sinch.sdk.domains.sms.models.v1.batches.response.Batch deserialize( + JsonParser jp, DeserializationContext ctxt) throws IOException { + + Object deserialized = jp.readValueAs(BatchResponseInternalImpl.class).getActualInstance(); + if (null == deserialized) { + return null; + } + if (!(deserialized instanceof com.sinch.sdk.domains.sms.models.v1.batches.response.Batch)) { + log.log(Level.SEVERE, "Input data does not match schema ", deserialized); + return null; + } + + return (com.sinch.sdk.domains.sms.models.v1.batches.response.Batch) deserialized; + } + } +} From 6ad8141f1b1f0117742c54f46198e7fc9b035fe8 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 08:20:26 +0100 Subject: [PATCH 20/65] feat (SMS): Add guard against null SMS URL for service plan id usage --- .../com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index 69b58844e..84bde85fa 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -61,6 +61,7 @@ public SMSService( Objects.requireNonNull(context, "Context must be defined"); StringUtil.requireNonEmpty(credentials.getServicePlanId(), "'servicePlanId' must be defined"); StringUtil.requireNonEmpty(credentials.getApiToken(), "'apiToken' must be defined"); + StringUtil.requireNonEmpty(context.getSmsUrl(), "'smsUrl' must be defined"); LOGGER.fine( "Activate SMS API with service plan ID support and server='" From 21dddce4fe1532fdbf34162da1311d683c1315b7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 08:23:15 +0100 Subject: [PATCH 21/65] test (SMS): Use valid phone number format for unit tests --- .../v1/batches/request/SendDeliveryFeedbackRequestTest.java | 2 +- .../v1/batches/request/SendDeliveryFeedbackRequestDto.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java index 581da9688..7deac30d5 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java @@ -19,7 +19,7 @@ void sendDeliveryFeedbackRequestRequestDto() throws JsonProcessingException, JSO SendDeliveryFeedbackRequest requestDTO = SendDeliveryFeedbackRequest.builder() - .setRecipients(Arrays.asList("foo number 1", "foo number 2")) + .setRecipients(Arrays.asList("+15551231234", "+15987365412")) .build(); String serializedString = objectMapper.writeValueAsString(requestDTO); diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json index be9141af0..cbbdfceb5 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json @@ -1,6 +1,6 @@ { "recipients": [ - "foo number 1", - "foo number 2" + "+15551231234", + "+15987365412" ] } From b37e9015d4fea4d35bbf1002cd95ce7852c139b7 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 08:29:40 +0100 Subject: [PATCH 22/65] test (SMS): Refactor test filenames --- ...RequestTest.java => SendDeliveryFeedbackRequestDtoTest.java} | 2 +- .../{SendBatchRequestDtoTest.java => SendRequestDtoTest.java} | 2 +- ...UpdateBatchRequestDtoTest.java => UpdateRequestDtoTest.java} | 2 +- .../{SendBatchResponseDtoTest.java => SendResponseDtoTest.java} | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/{SendDeliveryFeedbackRequestTest.java => SendDeliveryFeedbackRequestDtoTest.java} (94%) rename openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/{SendBatchRequestDtoTest.java => SendRequestDtoTest.java} (99%) rename openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/{UpdateBatchRequestDtoTest.java => UpdateRequestDtoTest.java} (99%) rename openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/{SendBatchResponseDtoTest.java => SendResponseDtoTest.java} (98%) diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestDtoTest.java similarity index 94% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestDtoTest.java index 7deac30d5..67f4ba8b3 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendDeliveryFeedbackRequestDtoTest.java @@ -10,7 +10,7 @@ import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources -class SendDeliveryFeedbackRequestTest extends BaseTest { +class SendDeliveryFeedbackRequestDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json") String jsonSendDeliveryFeedbackRequestDto; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendRequestDtoTest.java similarity index 99% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendRequestDtoTest.java index 6e473a46d..a614f0693 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendBatchRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/SendRequestDtoTest.java @@ -17,7 +17,7 @@ import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources -class SendBatchRequestDtoTest extends BaseTest { +class SendRequestDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/batches/request/BinaryRequestDto.json") String jsonRequestBinaryDto; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateRequestDtoTest.java similarity index 99% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateRequestDtoTest.java index e74d2f92a..71c3be634 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateRequestDtoTest.java @@ -17,7 +17,7 @@ import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources -class UpdateBatchRequestDtoTest extends BaseTest { +class UpdateRequestDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/batches/request/UpdateBinaryRequestDto.json") String jsonRequestBinaryDto; diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java similarity index 98% rename from openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java rename to openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java index ab5f6c325..3a8545939 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendBatchResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java @@ -15,7 +15,7 @@ import org.junit.jupiter.api.Test; @TestWithResources -class SendBatchResponseDtoTest extends BaseTest { +class SendResponseDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") Batch loadedBinaryDto; From b7b1d79ff06436d429dd2dec3eca6e227c95ec12 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 08:53:20 +0100 Subject: [PATCH 23/65] test (SMS): Extend SMS service init unit tests coverage --- .../sms/api/v1/adapters/SMSServiceTest.java | 134 ++++++++++++++++-- 1 file changed, 120 insertions(+), 14 deletions(-) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java index c09a23306..c520d8d4b 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/SMSServiceTest.java @@ -1,11 +1,13 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.models.SmsContext; +import com.sinch.sdk.models.SmsServicePlanCredentials; import com.sinch.sdk.models.UnifiedCredentials; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -15,11 +17,11 @@ class SMSServiceTest { @Mock HttpClient httpClient; @Test - void doNotAcceptNullKey() { + void projectIdDoNotAcceptNullKey() { UnifiedCredentials credentials = UnifiedCredentials.builder().setKeyId(null).setKeySecret("foo").setProjectId("foo").build(); - SmsContext context = SmsContext.builder().build(); - ServerConfiguration server = new ServerConfiguration(""); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); Exception exception = assertThrows( IllegalArgumentException.class, @@ -28,11 +30,11 @@ void doNotAcceptNullKey() { } @Test - void doNotAcceptNullKeySecret() { + void projectIdDoNotAcceptNullKeySecret() { UnifiedCredentials credentials = UnifiedCredentials.builder().setKeyId("foo").setKeySecret(null).setProjectId("foo").build(); - SmsContext context = SmsContext.builder().build(); - ServerConfiguration server = new ServerConfiguration(""); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); Exception exception = assertThrows( IllegalArgumentException.class, @@ -41,11 +43,11 @@ void doNotAcceptNullKeySecret() { } @Test - void doNotAcceptNullProject() { + void projectIdDoNotAcceptNullProject() { UnifiedCredentials credentials = UnifiedCredentials.builder().setKeyId("foo").setKeySecret("foo").setProjectId(null).build(); - SmsContext context = SmsContext.builder().build(); - ServerConfiguration server = new ServerConfiguration(""); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); Exception exception = assertThrows( @@ -55,10 +57,10 @@ void doNotAcceptNullProject() { } @Test - void doNotAcceptNullCredentials() { + void projectIdDoNotAcceptNullCredentials() { - SmsContext context = SmsContext.builder().build(); - ServerConfiguration server = new ServerConfiguration(""); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); Exception exception = assertThrows( NullPointerException.class, () -> new SMSService(null, context, server, httpClient)); @@ -66,18 +68,122 @@ void doNotAcceptNullCredentials() { } @Test - void doNotAcceptNullContext() { + void projectIdDoNotAcceptNullContext() { UnifiedCredentials credentials = UnifiedCredentials.builder() .setKeyId("foo") .setKeySecret("foo") .setProjectId("foo") .build(); - ServerConfiguration server = new ServerConfiguration(""); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); Exception exception = assertThrows( NullPointerException.class, () -> new SMSService(credentials, null, server, httpClient)); assertTrue(exception.getMessage().contains("Context must be defined")); } + + @Test + void projectIdDoNotAcceptNullSmsUrl() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + SmsContext context = SmsContext.builder().setSmsUrl(null).build(); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new SMSService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("smsUrl")); + } + + @Test + void projectIdUsagePassed() { + + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo key ") + .setKeySecret("foo secret") + .setProjectId("foo project") + .build(); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + ServerConfiguration server = new ServerConfiguration("https://oauth.foo.url"); + + assertDoesNotThrow( + () -> new SMSService(credentials, context, server, httpClient), "Init passed"); + } + + @Test + void servicePlanIdDoNotAcceptNullApiToken() { + SmsServicePlanCredentials credentials = + SmsServicePlanCredentials.builder().setApiToken(null).setServicePlanId("foo plan").build(); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + Exception exception = + assertThrows( + IllegalArgumentException.class, () -> new SMSService(credentials, context, httpClient)); + assertTrue(exception.getMessage().contains("apiToken")); + } + + @Test + void servicePlanIdDoNotAcceptNullServicePlanId() { + SmsServicePlanCredentials credentials = + SmsServicePlanCredentials.builder().setApiToken("foo token").setServicePlanId(null).build(); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + Exception exception = + assertThrows( + IllegalArgumentException.class, () -> new SMSService(credentials, context, httpClient)); + assertTrue(exception.getMessage().contains("servicePlanId")); + } + + @Test + void servicePlanIdDoNotAcceptNullCredentials() { + + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + Exception exception = + assertThrows(NullPointerException.class, () -> new SMSService(null, context, httpClient)); + assertTrue(exception.getMessage().contains("Credentials must be defined")); + } + + @Test + void servicePlanIdDoNotAcceptNullContext() { + SmsServicePlanCredentials credentials = + SmsServicePlanCredentials.builder() + .setApiToken("foo token") + .setServicePlanId("foo plan") + .build(); + Exception exception = + assertThrows( + NullPointerException.class, () -> new SMSService(credentials, null, httpClient)); + assertTrue(exception.getMessage().contains("Context must be defined")); + } + + @Test + void servicePlanIdDoNotAcceptNullSmsUrl() { + SmsServicePlanCredentials credentials = + SmsServicePlanCredentials.builder() + .setApiToken("foo token") + .setServicePlanId("foo plan") + .build(); + SmsContext context = SmsContext.builder().setSmsUrl(null).build(); + Exception exception = + assertThrows( + IllegalArgumentException.class, () -> new SMSService(credentials, context, httpClient)); + assertTrue(exception.getMessage().contains("smsUrl")); + } + + @Test + void servicePlanIdUsagePassed() { + + SmsServicePlanCredentials credentials = + SmsServicePlanCredentials.builder() + .setApiToken("foo token") + .setServicePlanId("foo plan") + .build(); + SmsContext context = SmsContext.builder().setSmsUrl("https://sms.foo.url").build(); + + assertDoesNotThrow(() -> new SMSService(credentials, context, httpClient), "Init passed"); + } } From 79fa747cbd761f0a9d7ca6a81328200ded3aff0e Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 11:41:54 +0100 Subject: [PATCH 24/65] refactor (SMS/Batches): Rename 'Batch' class with 'BatchResponse' --- .../domains/sms/api/v1/BatchesService.java | 12 ++-- .../sms/api/v1/adapters/BatchesService.java | 12 ++-- .../{Batch.java => BatchResponse.java} | 2 +- .../batches/response/ListBatchesResponse.java | 8 +-- .../sms/adapters/BatchesServiceTest.java | 6 +- .../converters/BatchDtoConverterTest.java | 6 +- .../api/v1/adapters/BatchesServiceTest.java | 68 +++++++++---------- .../sdk/e2e/domains/sms/v1/BatchesSteps.java | 40 +++++------ .../models/dto/v1/BinaryResponseDtoTest.java | 4 +- .../models/dto/v1/MediaResponseDtoTest.java | 2 +- .../models/dto/v1/SendSMSResponseDtoTest.java | 6 +- .../models/dto/v1/TextResponseDtoTest.java | 4 +- .../batches/response/SendResponseDtoTest.java | 24 +++---- ...hBinaryDto.json => BinaryResponseDto.json} | 0 ...tchMediaDto.json => MediaResponseDto.json} | 0 ...BatchTextDto.json => TextResponseDto.json} | 0 .../sinch/sample/sms/v1/batches/Cancel.java | 4 +- .../com/sinch/sample/sms/v1/batches/Get.java | 4 +- .../sinch/sample/sms/v1/batches/Replace.java | 4 +- .../com/sinch/sample/sms/v1/batches/Send.java | 4 +- .../sinch/sample/sms/v1/batches/Update.java | 4 +- 21 files changed, 107 insertions(+), 107 deletions(-) rename client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{Batch.java => BatchResponse.java} (89%) rename openapi-contracts/src/test/resources/domains/sms/v1/batches/response/{BatchBinaryDto.json => BinaryResponseDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/batches/response/{BatchMediaDto.json => MediaResponseDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/batches/response/{BatchTextDto.json => TextResponseDto.json} (100%) diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 449491e4c..c83cbcec8 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -5,26 +5,26 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; public interface BatchesService { - Batch send(BatchRequest batch) throws ApiException; + BatchResponse send(BatchRequest batch) throws ApiException; ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); - Batch get(String batchId) throws ApiException; + BatchResponse get(String batchId) throws ApiException; - Batch replace(String batchId, BatchRequest batch) throws ApiException; + BatchResponse replace(String batchId, BatchRequest batch) throws ApiException; - Batch cancel(String batchId) throws ApiException; + BatchResponse cancel(String batchId) throws ApiException; void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest recipients) throws ApiException; - Batch update(String batchId, UpdateBatchRequest request) throws ApiException; + BatchResponse update(String batchId, UpdateBatchRequest request) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index e32033317..b2d4d166b 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -11,7 +11,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; @@ -36,7 +36,7 @@ protected BatchesApi getApi() { return this.api; } - public Batch send(BatchRequest batch) throws ApiException { + public BatchResponse send(BatchRequest batch) throws ApiException { return getApi().send(batch); } @@ -66,15 +66,15 @@ public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchR return getApi().dryRun(perRecipient, numberOfRecipient, batch); } - public Batch get(String batchId) throws ApiException { + public BatchResponse get(String batchId) throws ApiException { return getApi().get(batchId); } - public Batch replace(String batchId, BatchRequest batch) throws ApiException { + public BatchResponse replace(String batchId, BatchRequest batch) throws ApiException { return getApi().replace(batchId, batch); } - public Batch cancel(String batchId) throws ApiException { + public BatchResponse cancel(String batchId) throws ApiException { return getApi().cancel(batchId); } @@ -83,7 +83,7 @@ public void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest req getApi().sendDeliveryFeedback(batchId, request); } - public Batch update(String batchId, UpdateBatchRequest request) throws ApiException { + public BatchResponse update(String batchId, UpdateBatchRequest request) throws ApiException { return getApi().update(batchId, request); } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchResponse.java similarity index 89% rename from client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java rename to client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchResponse.java index 71c101738..f44bed4bd 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/Batch.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchResponse.java @@ -4,4 +4,4 @@ import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.BatchResponseInternalImpl; @JsonDeserialize(using = BatchResponseInternalImpl.Deserializer.class) -public interface Batch {} +public interface BatchResponse {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java index 34353487f..20a0ce6bd 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java @@ -7,14 +7,14 @@ import java.util.Collection; import java.util.NoSuchElementException; -public class ListBatchesResponse extends ListResponse { +public class ListBatchesResponse extends ListResponse { - private final Page page; + private final Page page; private final BatchesService service; private ListBatchesResponse nextPage; public ListBatchesResponse( - BatchesService service, Page page) { + BatchesService service, Page page) { this.service = service; this.page = page; } @@ -40,7 +40,7 @@ public ListBatchesResponse nextPage() { return response; } - public Collection getContent() { + public Collection getContent() { return page.getEntities(); } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java index 493f389fa..e2b2b1ad2 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/BatchesServiceTest.java @@ -246,13 +246,13 @@ public class BatchesServiceTest extends BaseTest { .setUdh(udh) .build(); - @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") public SendSMS201ResponseDto binaryResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") SendSMS201ResponseDto mediaResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") SendSMS201ResponseDto textResponseDto; @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java index 9647a6324..22ea01b7e 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/BatchDtoConverterTest.java @@ -27,13 +27,13 @@ @TestWithResources class BatchDtoConverterTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") public SendSMS201ResponseDto binaryResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") public SendSMS201ResponseDto textResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") public SendSMS201ResponseDto mediaResponseDto; @GivenJsonResource("/domains/sms/v1/BinaryRequestDto.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java index 6a66dfaf7..67189c06c 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java @@ -24,12 +24,12 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBinaryRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateMediaRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchBinary; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchMedia; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchText; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BinaryResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.MediaResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.TextResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; import com.sinch.sdk.models.SmsContext; import java.time.Instant; @@ -70,8 +70,8 @@ public class BatchesServiceTest extends BaseTest { static final int fromNpi = 18; static final String udh = "foo udh"; static final String body = "Hi ${name} ({an identifier}) ! How are you?"; - public static final BatchBinary batchBinary = - BatchBinary.builder() + public static final BinaryResponse batchBinary = + BinaryResponse.builder() .setId(id) .setTo(to) .setFrom(from) @@ -109,8 +109,8 @@ public class BatchesServiceTest extends BaseTest { new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - public static final BatchMedia batchMedia = - BatchMedia.builder() + public static final MediaResponse batchMedia = + MediaResponse.builder() .setId(id) .setTo(to) .setFrom(from) @@ -133,8 +133,8 @@ public class BatchesServiceTest extends BaseTest { .setStrictValidation(true) .setParameters(parameters) .build(); - public static final BatchText batchText = - BatchText.builder() + public static final TextResponse batchText = + TextResponse.builder() .setId(id) .setTo(to) .setFrom(from) @@ -248,14 +248,14 @@ public class BatchesServiceTest extends BaseTest { .setUdh(udh) .build(); - @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") - public Batch binaryResponseDto; + @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") + public BatchResponse binaryResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") - Batch mediaResponseDto; + @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") + BatchResponse mediaResponseDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") - Batch textResponseDto; + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") + BatchResponse textResponseDto; @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") DryRunResponse dryRunResponseDto; @@ -289,7 +289,7 @@ void getBinary() throws ApiException { when(api.get(eq("foo binary batch id"))).thenReturn(binaryResponseDto); - Batch response = service.get("foo binary batch id"); + BatchResponse response = service.get("foo binary batch id"); TestHelpers.recursiveEquals(response, batchBinary); } @@ -299,7 +299,7 @@ void getMedia() throws ApiException { when(api.get(eq("foo media batch id"))).thenReturn(mediaResponseDto); - Batch response = service.get("foo media batch id"); + BatchResponse response = service.get("foo media batch id"); TestHelpers.recursiveEquals(response, batchMedia); } @@ -309,7 +309,7 @@ void getText() throws ApiException { when(api.get(eq("foo text batch id"))).thenReturn(textResponseDto); - Batch response = service.get("foo text batch id"); + BatchResponse response = service.get("foo text batch id"); TestHelpers.recursiveEquals(response, batchText); } @@ -319,7 +319,7 @@ void sendBinary() throws ApiException { when(api.send(sendSmsBatchBinaryRequest)).thenReturn(binaryResponseDto); - Batch response = service.send(sendSmsBatchBinaryRequest); + BatchResponse response = service.send(sendSmsBatchBinaryRequest); TestHelpers.recursiveEquals(response, batchBinary); } @@ -329,7 +329,7 @@ void sendMedia() throws ApiException { when(api.send(sendSmsBatchMediaRequest)).thenReturn(mediaResponseDto); - Batch response = service.send(sendSmsBatchMediaRequest); + BatchResponse response = service.send(sendSmsBatchMediaRequest); TestHelpers.recursiveEquals(response, batchMedia); } @@ -339,7 +339,7 @@ void sendText() throws ApiException { when(api.send(sendSmsBatchTextRequest)).thenReturn(textResponseDto); - Batch response = service.send(sendSmsBatchTextRequest); + BatchResponse response = service.send(sendSmsBatchTextRequest); TestHelpers.recursiveEquals(response, batchText); } @@ -365,12 +365,12 @@ void list() throws ApiException { .thenReturn(listBatchesResponseDtoPage2); ListBatchesResponse response = service.list(null); - Iterator iterator = response.iterator(); - Batch batch = iterator.next(); + Iterator iterator = response.iterator(); + BatchResponse batch = iterator.next(); Assertions.assertThat(iterator.hasNext()).isEqualTo(true); TestHelpers.recursiveEquals( batch, - BatchBinary.builder() + BinaryResponse.builder() .setId("01HEAWCHESCXG8SDG5R10VF8E1") .setTo(Collections.singletonList("339876543213")) .setFrom("33123456789") @@ -388,7 +388,7 @@ void list() throws ApiException { Assertions.assertThat(iterator.hasNext()).isEqualTo(true); TestHelpers.recursiveEquals( batch, - BatchText.builder() + TextResponse.builder() .setId("01HEAC0AG69SVYYQ675VPYT28Q") .setTo(Collections.singletonList("3300000000")) .setCanceled(false) @@ -405,7 +405,7 @@ void list() throws ApiException { Assertions.assertThat(iterator.hasNext()).isEqualTo(false); TestHelpers.recursiveEquals( batch, - BatchMedia.builder() + MediaResponse.builder() .setId("01HEABZ9S80D4ENE3X6CPMATZR") .setTo(Collections.singletonList("331111111")) .setCanceled(false) @@ -424,7 +424,7 @@ void updateText() throws ApiException { when(api.update(eq("foo text batch id"), eq(updateSmsBatchTextRequest))) .thenReturn(textResponseDto); - Batch response = service.update("foo text batch id", updateSmsBatchTextRequest); + BatchResponse response = service.update("foo text batch id", updateSmsBatchTextRequest); TestHelpers.recursiveEquals(response, batchText); } @@ -435,7 +435,7 @@ void updateMedia() throws ApiException { when(api.update(eq("foo text batch id"), eq(updateSmsBatchMediaRequest))) .thenReturn(mediaResponseDto); - Batch response = service.update("foo text batch id", updateSmsBatchMediaRequest); + BatchResponse response = service.update("foo text batch id", updateSmsBatchMediaRequest); TestHelpers.recursiveEquals(response, batchMedia); } @@ -446,7 +446,7 @@ void updateBinary() throws ApiException { when(api.update(eq("foo text batch id"), eq(updateSmsBatchBinaryRequest))) .thenReturn(binaryResponseDto); - Batch response = service.update("foo text batch id", updateSmsBatchBinaryRequest); + BatchResponse response = service.update("foo text batch id", updateSmsBatchBinaryRequest); TestHelpers.recursiveEquals(response, batchBinary); } @@ -457,7 +457,7 @@ void replaceBinary() throws ApiException { when(api.replace(eq("foo text batch id"), eq(sendSmsBatchBinaryRequest))) .thenReturn(binaryResponseDto); - Batch response = service.replace("foo text batch id", sendSmsBatchBinaryRequest); + BatchResponse response = service.replace("foo text batch id", sendSmsBatchBinaryRequest); TestHelpers.recursiveEquals(response, batchBinary); } @@ -468,7 +468,7 @@ void replaceMedia() throws ApiException { when(api.replace(eq("foo text batch id"), eq(sendSmsBatchMediaRequest))) .thenReturn(mediaResponseDto); - Batch response = service.replace("foo text batch id", sendSmsBatchMediaRequest); + BatchResponse response = service.replace("foo text batch id", sendSmsBatchMediaRequest); TestHelpers.recursiveEquals(response, batchMedia); } @@ -479,7 +479,7 @@ void replaceText() throws ApiException { when(api.replace(eq("foo text batch id"), eq(sendSmsBatchTextRequest))) .thenReturn(textResponseDto); - Batch response = service.replace("foo text batch id", sendSmsBatchTextRequest); + BatchResponse response = service.replace("foo text batch id", sendSmsBatchTextRequest); TestHelpers.recursiveEquals(response, batchText); } @@ -489,7 +489,7 @@ void cancelBatch() throws ApiException { when(api.cancel(eq("foo text batch id"))).thenReturn(textResponseDto); - Batch response = service.cancel("foo text batch id"); + BatchResponse response = service.cancel("foo text batch id"); TestHelpers.recursiveEquals(response, batchText); } diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java index 4db3b56d0..7d58a5f84 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java @@ -7,11 +7,11 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchText; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunPerRecipientDetails; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.TextResponse; import com.sinch.sdk.e2e.Config; import io.cucumber.java.en.Given; import io.cucumber.java.en.Then; @@ -30,16 +30,16 @@ public class BatchesSteps { BatchesService service; - Batch sendTextResponse; - Batch sendTextWithParametersResponse; + BatchResponse sendTextResponse; + BatchResponse sendTextWithParametersResponse; DryRunResponse dryRunResponse; ListBatchesResponse listOnePageResponse; ListBatchesResponse listAllResponse; ListBatchesResponse listAllByPageResponse; - Batch getBatchResponse; - Batch updateResponse; - Batch replaceResponse; - Batch cancelResponse; + BatchResponse getBatchResponse; + BatchResponse updateResponse; + BatchResponse replaceResponse; + BatchResponse cancelResponse; Boolean sendDeliveryFeedbackPassed; @Given("^the SMS service \"Batches\" is available") @@ -191,8 +191,8 @@ public void sendDeliveryFeedback() { @Then("the response contains the text SMS details") public void sendResult() { - BatchText expected = - BatchText.builder() + TextResponse expected = + TextResponse.builder() .setId("01W4FFL35P4NC4K35SMSBATCH1") .setTo(Collections.singletonList("12017777777")) .setFrom("12015555555") @@ -230,8 +230,8 @@ public void sendWithParametersResult() { new AbstractMap.SimpleEntry<>("code", codeParameters)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - BatchText expected = - BatchText.builder() + TextResponse expected = + TextResponse.builder() .setId("01W4FFL35P4NC4K35SMSBATCH2") .setTo(Arrays.asList("12017777777", "12018888888")) .setFrom("12015555555") @@ -313,8 +313,8 @@ public void listAllByPageResult(int expected) { @Then("the response contains the SMS batch details") public void getResult() { - BatchText expected = - BatchText.builder() + TextResponse expected = + TextResponse.builder() .setId("01W4FFL35P4NC4K35SMSBATCH1") .setTo(Collections.singletonList("12017777777")) .setFrom("12015555555") @@ -335,8 +335,8 @@ public void getResult() { @Then("the response contains the SMS batch details with updated data") public void updateResult() { - BatchText expected = - BatchText.builder() + TextResponse expected = + TextResponse.builder() .setId("01W4FFL35P4NC4K35SMSBATCH1") .setTo(Arrays.asList("12017777777", "01W4FFL35P4NC4K35SMSGROUP1")) .setFrom("12016666666") @@ -357,8 +357,8 @@ public void updateResult() { @Then("the response contains the new SMS batch details with the provided data for replacement") public void replaceResult() { - BatchText expected = - BatchText.builder() + TextResponse expected = + TextResponse.builder() .setId("01W4FFL35P4NC4K35SMSBATCH1") .setTo(Arrays.asList("12018888888")) .setFrom("12016666666") @@ -378,8 +378,8 @@ public void replaceResult() { @Then("the response contains the SMS batch details with a cancelled status") public void cancelResult() { - BatchText expected = - BatchText.builder() + TextResponse expected = + TextResponse.builder() .setId("01W4FFL35P4NC4K35SMSBATCH1") .setTo(Arrays.asList("12017777777")) .setFrom("12015555555") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java index 9e67b5e67..404545cf2 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/BinaryResponseDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources class BinaryResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") BinaryResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + @GivenTextResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") String jsonStringDto; BinaryResponseDto dto = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java index 2bf8b5951..57bf262d8 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MediaResponseDtoTest.java @@ -15,7 +15,7 @@ @TestWithResources class MediaResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") MediaResponseDto loadedDto; ParameterObjDto parameterObjDto = new ParameterObjDto(); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java index 28331ed1e..949037f15 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/SendSMSResponseDtoTest.java @@ -17,13 +17,13 @@ @TestWithResources class SendSMSResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") SendSMS201ResponseDto loadedBinary; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") SendSMS201ResponseDto loadedText; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") SendSMS201ResponseDto loadedMedia; ParameterObjDto parameterObjDto = new ParameterObjDto(); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java index 91b2808b5..debea95fa 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/TextResponseDtoTest.java @@ -19,10 +19,10 @@ @TestWithResources class TextResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") TextResponseDto loadedDto; - @GivenTextResource("/domains/sms/v1/batches/response/BatchTextDto.json") + @GivenTextResource("/domains/sms/v1/batches/response/TextResponseDto.json") String jsonStringDto; ParameterObjDto parameterObjDto = new ParameterObjDto(); diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java index 3a8545939..c40474adc 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/batches/response/SendResponseDtoTest.java @@ -16,17 +16,17 @@ @TestWithResources class SendResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/batches/response/BatchBinaryDto.json") - Batch loadedBinaryDto; + @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") + BatchResponse loadedBinaryDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchTextDto.json") - Batch loadedTextDto; + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") + BatchResponse loadedTextDto; - @GivenJsonResource("/domains/sms/v1/batches/response/BatchMediaDto.json") - Batch loadedMediaDto; + @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") + BatchResponse loadedMediaDto; - BatchBinary binaryResponseDto = - BatchBinary.builder() + BinaryResponse binaryResponseDto = + BinaryResponse.builder() .setBody("Hi ${name} ({an identifier}) ! How are you?") .setCallbackUrl("callback url") .setClientReference("myReference") @@ -63,8 +63,8 @@ class SendResponseDtoTest extends BaseTest { new AbstractMap.SimpleEntry<>("name", nameParameters), new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - BatchText textResponseDto = - BatchText.builder() + TextResponse textResponseDto = + TextResponse.builder() .setId("01FC66621XXXXX119Z8PMV1QPQ") .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) .setCanceled(false) @@ -86,8 +86,8 @@ class SendResponseDtoTest extends BaseTest { .setTruncateConcat(true) .build(); - BatchMedia mediaResponseDto = - BatchMedia.builder() + MediaResponse mediaResponseDto = + MediaResponse.builder() .setId("01FC66621XXXXX119Z8PMV1QPQ") .setCanceled(false) .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchBinaryDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BinaryResponseDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchBinaryDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BinaryResponseDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/MediaResponseDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchMediaDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/MediaResponseDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchTextDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/batches/response/TextResponseDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/batches/response/BatchTextDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/batches/response/TextResponseDto.json diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java index 7726f1d72..2b7893439 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Cancel.java @@ -2,7 +2,7 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.io.IOException; import java.util.logging.Logger; @@ -25,7 +25,7 @@ public void run() { BatchesService service = client.sms().v1().batches(); LOGGER.info("Cancelling batch: " + batchId); - Batch value = service.cancel(batchId); + BatchResponse value = service.cancel(batchId); LOGGER.info("Response: " + value); } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java index 2f3ea499e..273a98e6e 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Get.java @@ -2,7 +2,7 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.io.IOException; import java.util.logging.Logger; @@ -25,7 +25,7 @@ public void run() { BatchesService service = client.sms().v1().batches(); LOGGER.info("Get for :" + batchId); - Batch value = service.get(batchId); + BatchResponse value = service.get(batchId); LOGGER.info("Response :" + value); } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java index cfb10d906..8e64af257 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Replace.java @@ -3,7 +3,7 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.io.IOException; import java.util.Collections; import java.util.logging.Logger; @@ -27,7 +27,7 @@ public void run() { BatchesService service = client.sms().v1().batches(); LOGGER.info("Replace batch" + batchId); - Batch value = + BatchResponse value = service.replace( batchId, TextRequest.builder() diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java index 2b14dc146..f3abc50a3 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java @@ -4,7 +4,7 @@ import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.io.IOException; import java.util.AbstractMap; import java.util.Collections; @@ -61,7 +61,7 @@ public void run() { // Overload default dashboard webhooks URL if defined webhooksSmsPath.ifPresent(builder::setCallbackUrl); - Batch value = service.send(builder.build()); + BatchResponse value = service.send(builder.build()); LOGGER.info("Response: " + value); } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java index 2cd84e5e0..8344eaea1 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Update.java @@ -3,7 +3,7 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.io.IOException; import java.util.Collections; import java.util.logging.Logger; @@ -37,7 +37,7 @@ public void run() { webhooksSmsPath.ifPresent(builder::setCallbackUrl); - Batch value = service.update(batchId, builder.build()); + BatchResponse value = service.update(batchId, builder.build()); LOGGER.info("Response: " + value); } From 0a20f75eac400d3bfdfb99fcdce67a637ee75c3e Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 11:44:49 +0100 Subject: [PATCH 25/65] refactor (SMS/Batches): Generated files update --- .../sms/adapters/api/v1/BatchesApi.java | 4 +- .../sms/api/v1/internal/BatchesApi.java | 33 +-- .../batches/request/UpdateBinaryRequest.java | 2 +- .../request/UpdateBinaryRequestImpl.java | 3 +- .../batches/request/UpdateMediaRequest.java | 2 +- .../request/UpdateMediaRequestImpl.java | 3 +- .../v1/batches/request/UpdateTextRequest.java | 2 +- .../request/UpdateTextRequestImpl.java | 2 +- .../{BatchBinary.java => BinaryResponse.java} | 10 +- ...inaryImpl.java => BinaryResponseImpl.java} | 50 ++--- .../{BatchMedia.java => MediaResponse.java} | 10 +- ...hMediaImpl.java => MediaResponseImpl.java} | 48 ++--- .../{BatchText.java => TextResponse.java} | 10 +- ...tchTextImpl.java => TextResponseImpl.java} | 56 ++--- .../response/internal/ApiBatchList.java | 6 +- .../response/internal/ApiBatchListImpl.java | 14 +- .../internal/BatchResponseInternalImpl.java | 202 +++++++++--------- 17 files changed, 229 insertions(+), 228 deletions(-) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{BatchBinary.java => BinaryResponse.java} (97%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{BatchBinaryImpl.java => BinaryResponseImpl.java} (93%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{BatchMedia.java => MediaResponse.java} (97%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{BatchMediaImpl.java => MediaResponseImpl.java} (93%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{BatchText.java => TextResponse.java} (97%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/{BatchTextImpl.java => TextResponseImpl.java} (93%) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java index bd4b53145..50ee62f98 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/adapters/api/v1/BatchesApi.java @@ -761,8 +761,8 @@ private HttpRequest sendSMSRequestBuilder( } /** - * Update a Batch message This operation updates all specified parameters of a batch that matches - * the provided batch ID. + * Update a BatchResponse message This operation updates all specified parameters of a batch that + * matches the provided batch ID. * * @param servicePlanId Your service plan ID. You can find this on your * [Dashboard](https://dashboard.sinch.com/sms/api/rest). (required) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java index 3033d94dc..608bb175d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java @@ -26,7 +26,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; import java.util.ArrayList; @@ -69,10 +69,10 @@ public BatchesApi( * report. * * @param batchId The batch ID you received from sending a message. (required) - * @return Batch + * @return BatchResponse * @throws ApiException if fails to make API call */ - public Batch cancel(String batchId) throws ApiException { + public BatchResponse cancel(String batchId) throws ApiException { LOGGER.finest( "[cancel]" @@ -89,7 +89,7 @@ public Batch cancel(String batchId) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: @@ -247,10 +247,10 @@ private HttpRequest dryRunRequestBuilder( * Get a batch message This operation returns a specific batch that matches the provided batch ID. * * @param batchId The batch ID you received from sending a message. (required) - * @return Batch + * @return BatchResponse * @throws ApiException if fails to make API call */ - public Batch get(String batchId) throws ApiException { + public BatchResponse get(String batchId) throws ApiException { LOGGER.finest( "[get]" + " " + "this.servicePlanId: " + this.servicePlanId + ", " + "batchId: " + batchId); @@ -261,7 +261,7 @@ public Batch get(String batchId) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: @@ -463,10 +463,10 @@ private HttpRequest listRequestBuilder( * * @param batchId The batch ID you received from sending a message. (required) * @param sendRequest (optional) - * @return Batch + * @return BatchResponse * @throws ApiException if fails to make API call */ - public Batch replace(String batchId, BatchRequest sendRequest) throws ApiException { + public BatchResponse replace(String batchId, BatchRequest sendRequest) throws ApiException { LOGGER.finest( "[replace]" @@ -486,7 +486,7 @@ public Batch replace(String batchId, BatchRequest sendRequest) throws ApiExcepti this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: @@ -648,10 +648,10 @@ private HttpRequest sendDeliveryFeedbackRequestBuilder( * [region](/docs/sms/api-reference/#base-url) in the server URL. * * @param sendRequest Default schema is Text if type is not specified. (optional) - * @return Batch + * @return BatchResponse * @throws ApiException if fails to make API call */ - public Batch send(BatchRequest sendRequest) throws ApiException { + public BatchResponse send(BatchRequest sendRequest) throws ApiException { LOGGER.finest( "[send]" @@ -668,7 +668,7 @@ public Batch send(BatchRequest sendRequest) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: @@ -721,10 +721,11 @@ private HttpRequest sendRequestBuilder(BatchRequest sendRequest) throws ApiExcep * * @param batchId The batch ID you received from sending a message. (required) * @param updateBatchRequest (optional) - * @return Batch + * @return BatchResponse * @throws ApiException if fails to make API call */ - public Batch update(String batchId, UpdateBatchRequest updateBatchRequest) throws ApiException { + public BatchResponse update(String batchId, UpdateBatchRequest updateBatchRequest) + throws ApiException { LOGGER.finest( "[update]" @@ -744,7 +745,7 @@ public Batch update(String batchId, UpdateBatchRequest updateBatchRequest) throw this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; + TypeReference localVarReturnType = new TypeReference() {}; return mapper.deserialize(response, localVarReturnType); } // fallback to default errors handling: diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java index e0696bb75..4bfcc1c9d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java @@ -21,7 +21,7 @@ /** Update binary message */ @JsonDeserialize(builder = UpdateBinaryRequestImpl.Builder.class) -public interface UpdateBinaryRequest extends UpdateBatchRequest, BatchRequest { +public interface UpdateBinaryRequest extends UpdateBatchRequest { /** * Sender number. Must be valid phone number, short code or alphanumeric. diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java index 9e3dc24fc..0366125d0 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequestImpl.java @@ -30,8 +30,7 @@ }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class UpdateBinaryRequestImpl - implements UpdateBinaryRequest, UpdateBatchRequest, BatchRequest { +public class UpdateBinaryRequestImpl implements UpdateBinaryRequest, UpdateBatchRequest { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_FROM = "from"; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java index 5041cbcf6..bf48b7482 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequest.java @@ -23,7 +23,7 @@ /** Update media message */ @JsonDeserialize(builder = UpdateMediaRequestImpl.Builder.class) -public interface UpdateMediaRequest extends UpdateBatchRequest, BatchRequest { +public interface UpdateMediaRequest extends UpdateBatchRequest { /** * Sender number. Must be valid phone number, short code or alphanumeric. diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java index 41f6e8743..f9a2ae49a 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateMediaRequestImpl.java @@ -31,8 +31,7 @@ }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class UpdateMediaRequestImpl - implements UpdateMediaRequest, UpdateBatchRequest, BatchRequest { +public class UpdateMediaRequestImpl implements UpdateMediaRequest, UpdateBatchRequest { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_FROM = "from"; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java index 7f7482592..ca8b8a76d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequest.java @@ -22,7 +22,7 @@ /** Update text message */ @JsonDeserialize(builder = UpdateTextRequestImpl.Builder.class) -public interface UpdateTextRequest extends UpdateBatchRequest, BatchRequest { +public interface UpdateTextRequest extends UpdateBatchRequest { /** * Sender number. Must be valid phone number, short code or alphanumeric. diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java index ece635e2c..bca9c48ec 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateTextRequestImpl.java @@ -34,7 +34,7 @@ }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class UpdateTextRequestImpl implements UpdateTextRequest, UpdateBatchRequest, BatchRequest { +public class UpdateTextRequestImpl implements UpdateTextRequest, UpdateBatchRequest { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_FROM = "from"; diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BinaryResponse.java similarity index 97% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BinaryResponse.java index afeae44af..3b0db8b77 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinary.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BinaryResponse.java @@ -19,9 +19,9 @@ import java.util.List; import java.util.stream.Stream; -/** BatchBinary */ -@JsonDeserialize(builder = BatchBinaryImpl.Builder.class) -public interface BatchBinary extends Batch { +/** BinaryResponse */ +@JsonDeserialize(builder = BinaryResponseImpl.Builder.class) +public interface BinaryResponse extends BatchResponse { /** * Unique identifier for batch. @@ -190,7 +190,7 @@ public static String valueOf(TypeEnum e) { * @return New Builder instance */ static Builder builder() { - return new BatchBinaryImpl.Builder(); + return new BinaryResponseImpl.Builder(); } /** Dedicated Builder */ @@ -349,6 +349,6 @@ interface Builder { * * @return The instance build with current builder values */ - BatchBinary build(); + BinaryResponse build(); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BinaryResponseImpl.java similarity index 93% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BinaryResponseImpl.java index 6958afacc..fafac3b55 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchBinaryImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BinaryResponseImpl.java @@ -13,27 +13,27 @@ import java.util.Objects; @JsonPropertyOrder({ - BatchBinaryImpl.JSON_PROPERTY_ID, - BatchBinaryImpl.JSON_PROPERTY_TO, - BatchBinaryImpl.JSON_PROPERTY_FROM, - BatchBinaryImpl.JSON_PROPERTY_CANCELED, - BatchBinaryImpl.JSON_PROPERTY_BODY, - BatchBinaryImpl.JSON_PROPERTY_UDH, - BatchBinaryImpl.JSON_PROPERTY_TYPE, - BatchBinaryImpl.JSON_PROPERTY_CREATED_AT, - BatchBinaryImpl.JSON_PROPERTY_MODIFIED_AT, - BatchBinaryImpl.JSON_PROPERTY_DELIVERY_REPORT, - BatchBinaryImpl.JSON_PROPERTY_SEND_AT, - BatchBinaryImpl.JSON_PROPERTY_EXPIRE_AT, - BatchBinaryImpl.JSON_PROPERTY_CALLBACK_URL, - BatchBinaryImpl.JSON_PROPERTY_CLIENT_REFERENCE, - BatchBinaryImpl.JSON_PROPERTY_FEEDBACK_ENABLED, - BatchBinaryImpl.JSON_PROPERTY_FROM_TON, - BatchBinaryImpl.JSON_PROPERTY_FROM_NPI + BinaryResponseImpl.JSON_PROPERTY_ID, + BinaryResponseImpl.JSON_PROPERTY_TO, + BinaryResponseImpl.JSON_PROPERTY_FROM, + BinaryResponseImpl.JSON_PROPERTY_CANCELED, + BinaryResponseImpl.JSON_PROPERTY_BODY, + BinaryResponseImpl.JSON_PROPERTY_UDH, + BinaryResponseImpl.JSON_PROPERTY_TYPE, + BinaryResponseImpl.JSON_PROPERTY_CREATED_AT, + BinaryResponseImpl.JSON_PROPERTY_MODIFIED_AT, + BinaryResponseImpl.JSON_PROPERTY_DELIVERY_REPORT, + BinaryResponseImpl.JSON_PROPERTY_SEND_AT, + BinaryResponseImpl.JSON_PROPERTY_EXPIRE_AT, + BinaryResponseImpl.JSON_PROPERTY_CALLBACK_URL, + BinaryResponseImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BinaryResponseImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + BinaryResponseImpl.JSON_PROPERTY_FROM_TON, + BinaryResponseImpl.JSON_PROPERTY_FROM_NPI }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class BatchBinaryImpl implements BatchBinary, Batch { +public class BinaryResponseImpl implements BinaryResponse, BatchResponse { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_ID = "id"; @@ -104,9 +104,9 @@ public class BatchBinaryImpl implements BatchBinary, Batch { private OptionalValue fromNpi; - public BatchBinaryImpl() {} + public BinaryResponseImpl() {} - protected BatchBinaryImpl( + protected BinaryResponseImpl( OptionalValue id, OptionalValue> to, OptionalValue from, @@ -335,7 +335,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - BatchBinaryImpl binaryResponse = (BatchBinaryImpl) o; + BinaryResponseImpl binaryResponse = (BinaryResponseImpl) o; return Objects.equals(this.id, binaryResponse.id) && Objects.equals(this.to, binaryResponse.to) && Objects.equals(this.from, binaryResponse.from) @@ -380,7 +380,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class BatchBinaryImpl {\n"); + sb.append("class BinaryResponseImpl {\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" to: ").append(toIndentedString(to)).append("\n"); sb.append(" from: ").append(toIndentedString(from)).append("\n"); @@ -413,7 +413,7 @@ private String toIndentedString(Object o) { } @JsonPOJOBuilder(withPrefix = "set") - static class Builder implements BatchBinary.Builder { + static class Builder implements BinaryResponse.Builder { OptionalValue id = OptionalValue.empty(); OptionalValue> to = OptionalValue.empty(); OptionalValue from = OptionalValue.empty(); @@ -528,8 +528,8 @@ public Builder setFromNpi(Integer fromNpi) { return this; } - public BatchBinary build() { - return new BatchBinaryImpl( + public BinaryResponse build() { + return new BinaryResponseImpl( id, to, from, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/MediaResponse.java similarity index 97% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/MediaResponse.java index e00186837..3a2fd50f4 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMedia.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/MediaResponse.java @@ -21,9 +21,9 @@ import java.util.Map; import java.util.stream.Stream; -/** BatchMedia */ -@JsonDeserialize(builder = BatchMediaImpl.Builder.class) -public interface BatchMedia extends Batch { +/** MediaResponse */ +@JsonDeserialize(builder = MediaResponseImpl.Builder.class) +public interface MediaResponse extends BatchResponse { /** * Unique identifier for batch @@ -176,7 +176,7 @@ public static String valueOf(TypeEnum e) { * @return New Builder instance */ static Builder builder() { - return new BatchMediaImpl.Builder(); + return new MediaResponseImpl.Builder(); } /** Dedicated Builder */ @@ -326,6 +326,6 @@ interface Builder { * * @return The instance build with current builder values */ - BatchMedia build(); + MediaResponse build(); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/MediaResponseImpl.java similarity index 93% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/MediaResponseImpl.java index 4d64ba67c..cc0d03c06 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchMediaImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/MediaResponseImpl.java @@ -15,26 +15,26 @@ import java.util.Objects; @JsonPropertyOrder({ - BatchMediaImpl.JSON_PROPERTY_ID, - BatchMediaImpl.JSON_PROPERTY_TO, - BatchMediaImpl.JSON_PROPERTY_FROM, - BatchMediaImpl.JSON_PROPERTY_CANCELED, - BatchMediaImpl.JSON_PROPERTY_BODY, - BatchMediaImpl.JSON_PROPERTY_PARAMETERS, - BatchMediaImpl.JSON_PROPERTY_TYPE, - BatchMediaImpl.JSON_PROPERTY_CREATED_AT, - BatchMediaImpl.JSON_PROPERTY_MODIFIED_AT, - BatchMediaImpl.JSON_PROPERTY_DELIVERY_REPORT, - BatchMediaImpl.JSON_PROPERTY_SEND_AT, - BatchMediaImpl.JSON_PROPERTY_EXPIRE_AT, - BatchMediaImpl.JSON_PROPERTY_CALLBACK_URL, - BatchMediaImpl.JSON_PROPERTY_CLIENT_REFERENCE, - BatchMediaImpl.JSON_PROPERTY_FEEDBACK_ENABLED, - BatchMediaImpl.JSON_PROPERTY_STRICT_VALIDATION + MediaResponseImpl.JSON_PROPERTY_ID, + MediaResponseImpl.JSON_PROPERTY_TO, + MediaResponseImpl.JSON_PROPERTY_FROM, + MediaResponseImpl.JSON_PROPERTY_CANCELED, + MediaResponseImpl.JSON_PROPERTY_BODY, + MediaResponseImpl.JSON_PROPERTY_PARAMETERS, + MediaResponseImpl.JSON_PROPERTY_TYPE, + MediaResponseImpl.JSON_PROPERTY_CREATED_AT, + MediaResponseImpl.JSON_PROPERTY_MODIFIED_AT, + MediaResponseImpl.JSON_PROPERTY_DELIVERY_REPORT, + MediaResponseImpl.JSON_PROPERTY_SEND_AT, + MediaResponseImpl.JSON_PROPERTY_EXPIRE_AT, + MediaResponseImpl.JSON_PROPERTY_CALLBACK_URL, + MediaResponseImpl.JSON_PROPERTY_CLIENT_REFERENCE, + MediaResponseImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + MediaResponseImpl.JSON_PROPERTY_STRICT_VALIDATION }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class BatchMediaImpl implements BatchMedia, Batch { +public class MediaResponseImpl implements MediaResponse, BatchResponse { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_ID = "id"; @@ -101,9 +101,9 @@ public class BatchMediaImpl implements BatchMedia, Batch { private OptionalValue strictValidation; - public BatchMediaImpl() {} + public MediaResponseImpl() {} - protected BatchMediaImpl( + protected MediaResponseImpl( OptionalValue id, OptionalValue> to, OptionalValue from, @@ -318,7 +318,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - BatchMediaImpl mediaResponse = (BatchMediaImpl) o; + MediaResponseImpl mediaResponse = (MediaResponseImpl) o; return Objects.equals(this.id, mediaResponse.id) && Objects.equals(this.to, mediaResponse.to) && Objects.equals(this.from, mediaResponse.from) @@ -361,7 +361,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class BatchMediaImpl {\n"); + sb.append("class MediaResponseImpl {\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" to: ").append(toIndentedString(to)).append("\n"); sb.append(" from: ").append(toIndentedString(from)).append("\n"); @@ -393,7 +393,7 @@ private String toIndentedString(Object o) { } @JsonPOJOBuilder(withPrefix = "set") - static class Builder implements BatchMedia.Builder { + static class Builder implements MediaResponse.Builder { OptionalValue id = OptionalValue.empty(); OptionalValue> to = OptionalValue.empty(); OptionalValue from = OptionalValue.empty(); @@ -501,8 +501,8 @@ public Builder setStrictValidation(Boolean strictValidation) { return this; } - public BatchMedia build() { - return new BatchMediaImpl( + public MediaResponse build() { + return new MediaResponseImpl( id, to, from, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/TextResponse.java similarity index 97% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/TextResponse.java index 0d4dd2189..5cbeac7e9 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchText.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/TextResponse.java @@ -20,9 +20,9 @@ import java.util.Map; import java.util.stream.Stream; -/** BatchText */ -@JsonDeserialize(builder = BatchTextImpl.Builder.class) -public interface BatchText extends Batch { +/** TextResponse */ +@JsonDeserialize(builder = TextResponseImpl.Builder.class) +public interface TextResponse extends BatchResponse { /** * Unique identifier for batch @@ -215,7 +215,7 @@ public static String valueOf(TypeEnum e) { * @return New Builder instance */ static Builder builder() { - return new BatchTextImpl.Builder(); + return new TextResponseImpl.Builder(); } /** Dedicated Builder */ @@ -401,6 +401,6 @@ interface Builder { * * @return The instance build with current builder values */ - BatchText build(); + TextResponse build(); } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/TextResponseImpl.java similarity index 93% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/TextResponseImpl.java index 2786118d1..eb8a3cc9b 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/BatchTextImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/TextResponseImpl.java @@ -14,30 +14,30 @@ import java.util.Objects; @JsonPropertyOrder({ - BatchTextImpl.JSON_PROPERTY_ID, - BatchTextImpl.JSON_PROPERTY_TO, - BatchTextImpl.JSON_PROPERTY_FROM, - BatchTextImpl.JSON_PROPERTY_CANCELED, - BatchTextImpl.JSON_PROPERTY_PARAMETERS, - BatchTextImpl.JSON_PROPERTY_BODY, - BatchTextImpl.JSON_PROPERTY_TYPE, - BatchTextImpl.JSON_PROPERTY_CREATED_AT, - BatchTextImpl.JSON_PROPERTY_MODIFIED_AT, - BatchTextImpl.JSON_PROPERTY_DELIVERY_REPORT, - BatchTextImpl.JSON_PROPERTY_SEND_AT, - BatchTextImpl.JSON_PROPERTY_EXPIRE_AT, - BatchTextImpl.JSON_PROPERTY_CALLBACK_URL, - BatchTextImpl.JSON_PROPERTY_CLIENT_REFERENCE, - BatchTextImpl.JSON_PROPERTY_FEEDBACK_ENABLED, - BatchTextImpl.JSON_PROPERTY_FLASH_MESSAGE, - BatchTextImpl.JSON_PROPERTY_TRUNCATE_CONCAT, - BatchTextImpl.JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS, - BatchTextImpl.JSON_PROPERTY_FROM_TON, - BatchTextImpl.JSON_PROPERTY_FROM_NPI + TextResponseImpl.JSON_PROPERTY_ID, + TextResponseImpl.JSON_PROPERTY_TO, + TextResponseImpl.JSON_PROPERTY_FROM, + TextResponseImpl.JSON_PROPERTY_CANCELED, + TextResponseImpl.JSON_PROPERTY_PARAMETERS, + TextResponseImpl.JSON_PROPERTY_BODY, + TextResponseImpl.JSON_PROPERTY_TYPE, + TextResponseImpl.JSON_PROPERTY_CREATED_AT, + TextResponseImpl.JSON_PROPERTY_MODIFIED_AT, + TextResponseImpl.JSON_PROPERTY_DELIVERY_REPORT, + TextResponseImpl.JSON_PROPERTY_SEND_AT, + TextResponseImpl.JSON_PROPERTY_EXPIRE_AT, + TextResponseImpl.JSON_PROPERTY_CALLBACK_URL, + TextResponseImpl.JSON_PROPERTY_CLIENT_REFERENCE, + TextResponseImpl.JSON_PROPERTY_FEEDBACK_ENABLED, + TextResponseImpl.JSON_PROPERTY_FLASH_MESSAGE, + TextResponseImpl.JSON_PROPERTY_TRUNCATE_CONCAT, + TextResponseImpl.JSON_PROPERTY_MAX_NUMBER_OF_MESSAGE_PARTS, + TextResponseImpl.JSON_PROPERTY_FROM_TON, + TextResponseImpl.JSON_PROPERTY_FROM_NPI }) @JsonFilter("uninitializedFilter") @JsonInclude(value = JsonInclude.Include.CUSTOM) -public class BatchTextImpl implements BatchText, Batch { +public class TextResponseImpl implements TextResponse, BatchResponse { private static final long serialVersionUID = 1L; public static final String JSON_PROPERTY_ID = "id"; @@ -121,9 +121,9 @@ public class BatchTextImpl implements BatchText, Batch { private OptionalValue fromNpi; - public BatchTextImpl() {} + public TextResponseImpl() {} - protected BatchTextImpl( + protected TextResponseImpl( OptionalValue id, OptionalValue> to, OptionalValue from, @@ -390,7 +390,7 @@ public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) { return false; } - BatchTextImpl textResponse = (BatchTextImpl) o; + TextResponseImpl textResponse = (TextResponseImpl) o; return Objects.equals(this.id, textResponse.id) && Objects.equals(this.to, textResponse.to) && Objects.equals(this.from, textResponse.from) @@ -441,7 +441,7 @@ public int hashCode() { @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("class BatchTextImpl {\n"); + sb.append("class TextResponseImpl {\n"); sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" to: ").append(toIndentedString(to)).append("\n"); sb.append(" from: ").append(toIndentedString(from)).append("\n"); @@ -479,7 +479,7 @@ private String toIndentedString(Object o) { } @JsonPOJOBuilder(withPrefix = "set") - static class Builder implements BatchText.Builder { + static class Builder implements TextResponse.Builder { OptionalValue id = OptionalValue.empty(); OptionalValue> to = OptionalValue.empty(); OptionalValue from = OptionalValue.empty(); @@ -615,8 +615,8 @@ public Builder setFromNpi(Integer fromNpi) { return this; } - public BatchText build() { - return new BatchTextImpl( + public TextResponse build() { + return new TextResponseImpl( id, to, from, diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java index 22a925704..695ce3e06 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java @@ -11,7 +11,7 @@ package com.sinch.sdk.domains.sms.models.v1.batches.response.internal; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.util.List; /** ApiBatchList */ @@ -37,7 +37,7 @@ public interface ApiBatchList { * * @return batches */ - List getBatches(); + List getBatches(); /** * The number of entries returned in this request. @@ -83,7 +83,7 @@ interface Builder { * @return Current builder * @see #getBatches */ - Builder setBatches(List batches); + Builder setBatches(List batches); /** * see getter diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java index 43c44549a..24da89567 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java @@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sinch.sdk.core.models.OptionalValue; -import com.sinch.sdk.domains.sms.models.v1.batches.response.Batch; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import java.util.List; import java.util.Objects; @@ -32,7 +32,7 @@ public class ApiBatchListImpl implements ApiBatchList { public static final String JSON_PROPERTY_BATCHES = "batches"; - private OptionalValue> batches; + private OptionalValue> batches; public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; @@ -43,7 +43,7 @@ public ApiBatchListImpl() {} protected ApiBatchListImpl( OptionalValue count, OptionalValue page, - OptionalValue> batches, + OptionalValue> batches, OptionalValue pageSize) { this.count = count; this.page = page; @@ -74,13 +74,13 @@ public OptionalValue page() { } @JsonIgnore - public List getBatches() { + public List getBatches() { return batches.orElse(null); } @JsonProperty(JSON_PROPERTY_BATCHES) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue> batches() { + public OptionalValue> batches() { return batches; } @@ -142,7 +142,7 @@ private String toIndentedString(Object o) { static class Builder implements ApiBatchList.Builder { OptionalValue count = OptionalValue.empty(); OptionalValue page = OptionalValue.empty(); - OptionalValue> batches = OptionalValue.empty(); + OptionalValue> batches = OptionalValue.empty(); OptionalValue pageSize = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_COUNT) @@ -158,7 +158,7 @@ public Builder setPage(Integer page) { } @JsonProperty(JSON_PROPERTY_BATCHES) - public Builder setBatches(List batches) { + public Builder setBatches(List batches) { this.batches = OptionalValue.of(batches); return this; } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java index 5d58d1c29..57d7e0cea 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/BatchResponseInternalImpl.java @@ -16,9 +16,9 @@ import com.fasterxml.jackson.databind.ser.std.StdSerializer; import com.sinch.sdk.core.models.AbstractOpenApiSchema; import com.sinch.sdk.core.utils.databind.JSONNavigator; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchBinaryImpl; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchMediaImpl; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchTextImpl; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BinaryResponseImpl; +import com.sinch.sdk.domains.sms.models.v1.batches.response.MediaResponseImpl; +import com.sinch.sdk.domains.sms.models.v1.batches.response.TextResponseImpl; import java.io.IOException; import java.util.Collections; import java.util.HashMap; @@ -77,27 +77,27 @@ public BatchResponseInternalImpl deserialize(JsonParser jp, DeserializationConte String discriminatorValue = (String) result2.get("type"); switch (discriminatorValue) { case "mt_binary": - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchBinaryImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryResponseImpl.class); newBatchResponseInternalImpl.setActualInstance(deserialized); return newBatchResponseInternalImpl; case "mt_media": - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchMediaImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaResponseImpl.class); newBatchResponseInternalImpl.setActualInstance(deserialized); return newBatchResponseInternalImpl; case "mt_text": - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchTextImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextResponseImpl.class); newBatchResponseInternalImpl.setActualInstance(deserialized); return newBatchResponseInternalImpl; case "BinaryResponse": - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchBinaryImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryResponseImpl.class); newBatchResponseInternalImpl.setActualInstance(deserialized); return newBatchResponseInternalImpl; case "MediaResponse": - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchMediaImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaResponseImpl.class); newBatchResponseInternalImpl.setActualInstance(deserialized); return newBatchResponseInternalImpl; case "TextResponse": - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchTextImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextResponseImpl.class); newBatchResponseInternalImpl.setActualInstance(deserialized); return newBatchResponseInternalImpl; default: @@ -113,124 +113,124 @@ public BatchResponseInternalImpl deserialize(JsonParser jp, DeserializationConte boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); int match = 0; JsonToken token = tree.traverse(jp.getCodec()).nextToken(); - // deserialize BatchBinaryImpl + // deserialize BinaryResponseImpl try { boolean attemptParsing = true; // ensure that we respect type coercion as set on the client ObjectMapper - if (BatchBinaryImpl.class.equals(Integer.class) - || BatchBinaryImpl.class.equals(Long.class) - || BatchBinaryImpl.class.equals(Float.class) - || BatchBinaryImpl.class.equals(Double.class) - || BatchBinaryImpl.class.equals(Boolean.class) - || BatchBinaryImpl.class.equals(String.class)) { + if (BinaryResponseImpl.class.equals(Integer.class) + || BinaryResponseImpl.class.equals(Long.class) + || BinaryResponseImpl.class.equals(Float.class) + || BinaryResponseImpl.class.equals(Double.class) + || BinaryResponseImpl.class.equals(Boolean.class) + || BinaryResponseImpl.class.equals(String.class)) { attemptParsing = typeCoercion; if (!attemptParsing) { attemptParsing |= - ((BatchBinaryImpl.class.equals(Integer.class) - || BatchBinaryImpl.class.equals(Long.class)) + ((BinaryResponseImpl.class.equals(Integer.class) + || BinaryResponseImpl.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); attemptParsing |= - ((BatchBinaryImpl.class.equals(Float.class) - || BatchBinaryImpl.class.equals(Double.class)) + ((BinaryResponseImpl.class.equals(Float.class) + || BinaryResponseImpl.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); attemptParsing |= - (BatchBinaryImpl.class.equals(Boolean.class) + (BinaryResponseImpl.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); attemptParsing |= - (BatchBinaryImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + (BinaryResponseImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); } } if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchBinaryImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryResponseImpl.class); // TODO: there is no validation against JSON schema constraints // (min, max, enum, pattern...), this does not perform a strict JSON // validation, which means the 'match' count may be higher than it should be. match++; - log.log(Level.FINER, "Input data matches schema 'BatchBinaryImpl'"); + log.log(Level.FINER, "Input data matches schema 'BinaryResponseImpl'"); } } catch (Exception e) { // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'BatchBinaryImpl'", e); + log.log(Level.FINER, "Input data does not match schema 'BinaryResponseImpl'", e); } - // deserialize BatchMediaImpl + // deserialize MediaResponseImpl try { boolean attemptParsing = true; // ensure that we respect type coercion as set on the client ObjectMapper - if (BatchMediaImpl.class.equals(Integer.class) - || BatchMediaImpl.class.equals(Long.class) - || BatchMediaImpl.class.equals(Float.class) - || BatchMediaImpl.class.equals(Double.class) - || BatchMediaImpl.class.equals(Boolean.class) - || BatchMediaImpl.class.equals(String.class)) { + if (MediaResponseImpl.class.equals(Integer.class) + || MediaResponseImpl.class.equals(Long.class) + || MediaResponseImpl.class.equals(Float.class) + || MediaResponseImpl.class.equals(Double.class) + || MediaResponseImpl.class.equals(Boolean.class) + || MediaResponseImpl.class.equals(String.class)) { attemptParsing = typeCoercion; if (!attemptParsing) { attemptParsing |= - ((BatchMediaImpl.class.equals(Integer.class) - || BatchMediaImpl.class.equals(Long.class)) + ((MediaResponseImpl.class.equals(Integer.class) + || MediaResponseImpl.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); attemptParsing |= - ((BatchMediaImpl.class.equals(Float.class) - || BatchMediaImpl.class.equals(Double.class)) + ((MediaResponseImpl.class.equals(Float.class) + || MediaResponseImpl.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); attemptParsing |= - (BatchMediaImpl.class.equals(Boolean.class) + (MediaResponseImpl.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); attemptParsing |= - (BatchMediaImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + (MediaResponseImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); } } if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchMediaImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaResponseImpl.class); // TODO: there is no validation against JSON schema constraints // (min, max, enum, pattern...), this does not perform a strict JSON // validation, which means the 'match' count may be higher than it should be. match++; - log.log(Level.FINER, "Input data matches schema 'BatchMediaImpl'"); + log.log(Level.FINER, "Input data matches schema 'MediaResponseImpl'"); } } catch (Exception e) { // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'BatchMediaImpl'", e); + log.log(Level.FINER, "Input data does not match schema 'MediaResponseImpl'", e); } - // deserialize BatchTextImpl + // deserialize TextResponseImpl try { boolean attemptParsing = true; // ensure that we respect type coercion as set on the client ObjectMapper - if (BatchTextImpl.class.equals(Integer.class) - || BatchTextImpl.class.equals(Long.class) - || BatchTextImpl.class.equals(Float.class) - || BatchTextImpl.class.equals(Double.class) - || BatchTextImpl.class.equals(Boolean.class) - || BatchTextImpl.class.equals(String.class)) { + if (TextResponseImpl.class.equals(Integer.class) + || TextResponseImpl.class.equals(Long.class) + || TextResponseImpl.class.equals(Float.class) + || TextResponseImpl.class.equals(Double.class) + || TextResponseImpl.class.equals(Boolean.class) + || TextResponseImpl.class.equals(String.class)) { attemptParsing = typeCoercion; if (!attemptParsing) { attemptParsing |= - ((BatchTextImpl.class.equals(Integer.class) - || BatchTextImpl.class.equals(Long.class)) + ((TextResponseImpl.class.equals(Integer.class) + || TextResponseImpl.class.equals(Long.class)) && token == JsonToken.VALUE_NUMBER_INT); attemptParsing |= - ((BatchTextImpl.class.equals(Float.class) - || BatchTextImpl.class.equals(Double.class)) + ((TextResponseImpl.class.equals(Float.class) + || TextResponseImpl.class.equals(Double.class)) && token == JsonToken.VALUE_NUMBER_FLOAT); attemptParsing |= - (BatchTextImpl.class.equals(Boolean.class) + (TextResponseImpl.class.equals(Boolean.class) && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); attemptParsing |= - (BatchTextImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + (TextResponseImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); } } if (attemptParsing) { - deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchTextImpl.class); + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextResponseImpl.class); // TODO: there is no validation against JSON schema constraints // (min, max, enum, pattern...), this does not perform a strict JSON // validation, which means the 'match' count may be higher than it should be. match++; - log.log(Level.FINER, "Input data matches schema 'BatchTextImpl'"); + log.log(Level.FINER, "Input data matches schema 'TextResponseImpl'"); } } catch (Exception e) { // deserialization failed, continue - log.log(Level.FINER, "Input data does not match schema 'BatchTextImpl'", e); + log.log(Level.FINER, "Input data does not match schema 'TextResponseImpl'", e); } if (match == 1) { @@ -260,35 +260,35 @@ public BatchResponseInternalImpl() { super("oneOf", Boolean.FALSE); } - public BatchResponseInternalImpl(BatchBinaryImpl o) { + public BatchResponseInternalImpl(BinaryResponseImpl o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } - public BatchResponseInternalImpl(BatchMediaImpl o) { + public BatchResponseInternalImpl(MediaResponseImpl o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } - public BatchResponseInternalImpl(BatchTextImpl o) { + public BatchResponseInternalImpl(TextResponseImpl o) { super("oneOf", Boolean.FALSE); setActualInstance(o); } static { - schemas.put("BatchBinaryImpl", BatchBinaryImpl.class); - schemas.put("BatchMediaImpl", BatchMediaImpl.class); - schemas.put("BatchTextImpl", BatchTextImpl.class); + schemas.put("BinaryResponseImpl", BinaryResponseImpl.class); + schemas.put("MediaResponseImpl", MediaResponseImpl.class); + schemas.put("TextResponseImpl", TextResponseImpl.class); JSONNavigator.registerDescendants( BatchResponseInternalImpl.class, Collections.unmodifiableMap(schemas)); // Initialize and register the discriminator mappings. Map> mappings = new HashMap>(); - mappings.put("mt_binary", BatchBinaryImpl.class); - mappings.put("mt_media", BatchMediaImpl.class); - mappings.put("mt_text", BatchTextImpl.class); - mappings.put("BinaryResponse", BatchBinaryImpl.class); - mappings.put("MediaResponse", BatchMediaImpl.class); - mappings.put("TextResponse", BatchTextImpl.class); + mappings.put("mt_binary", BinaryResponseImpl.class); + mappings.put("mt_media", MediaResponseImpl.class); + mappings.put("mt_text", TextResponseImpl.class); + mappings.put("BinaryResponse", BinaryResponseImpl.class); + mappings.put("MediaResponse", MediaResponseImpl.class); + mappings.put("TextResponse", TextResponseImpl.class); mappings.put("Batch", BatchResponseInternalImpl.class); JSONNavigator.registerDiscriminator(BatchResponseInternalImpl.class, "type", mappings); } @@ -300,37 +300,37 @@ public Map> getSchemas() { /** * Set the instance that matches the oneOf child schema, check the instance parameter is valid - * against the oneOf child schemas: BatchBinaryImpl, BatchMediaImpl, BatchTextImpl + * against the oneOf child schemas: BinaryResponseImpl, MediaResponseImpl, TextResponseImpl * *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a * composed schema (allOf, anyOf, oneOf). */ @Override public void setActualInstance(Object instance) { - if (JSONNavigator.isInstanceOf(BatchBinaryImpl.class, instance, new HashSet>())) { + if (JSONNavigator.isInstanceOf(BinaryResponseImpl.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } - if (JSONNavigator.isInstanceOf(BatchMediaImpl.class, instance, new HashSet>())) { + if (JSONNavigator.isInstanceOf(MediaResponseImpl.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } - if (JSONNavigator.isInstanceOf(BatchTextImpl.class, instance, new HashSet>())) { + if (JSONNavigator.isInstanceOf(TextResponseImpl.class, instance, new HashSet>())) { super.setActualInstance(instance); return; } throw new RuntimeException( - "Invalid instance type. Must be BatchBinaryImpl, BatchMediaImpl, BatchTextImpl"); + "Invalid instance type. Must be BinaryResponseImpl, MediaResponseImpl, TextResponseImpl"); } /** - * Get the actual instance, which can be the following: BatchBinaryImpl, BatchMediaImpl, - * BatchTextImpl + * Get the actual instance, which can be the following: BinaryResponseImpl, MediaResponseImpl, + * TextResponseImpl * - * @return The actual instance (BatchBinaryImpl, BatchMediaImpl, BatchTextImpl) + * @return The actual instance (BinaryResponseImpl, MediaResponseImpl, TextResponseImpl) */ @Override public Object getActualInstance() { @@ -338,63 +338,65 @@ public Object getActualInstance() { } /** - * Get the actual instance of `BatchBinaryImpl`. If the actual instance is not `BatchBinaryImpl`, - * the ClassCastException will be thrown. + * Get the actual instance of `BinaryResponseImpl`. If the actual instance is not + * `BinaryResponseImpl`, the ClassCastException will be thrown. * - * @return The actual instance of `BatchBinaryImpl` - * @throws ClassCastException if the instance is not `BatchBinaryImpl` + * @return The actual instance of `BinaryResponseImpl` + * @throws ClassCastException if the instance is not `BinaryResponseImpl` */ - public BatchBinaryImpl getBatchBinaryImpl() throws ClassCastException { - return (BatchBinaryImpl) super.getActualInstance(); + public BinaryResponseImpl getBinaryResponseImpl() throws ClassCastException { + return (BinaryResponseImpl) super.getActualInstance(); } /** - * Get the actual instance of `BatchMediaImpl`. If the actual instance is not `BatchMediaImpl`, - * the ClassCastException will be thrown. + * Get the actual instance of `MediaResponseImpl`. If the actual instance is not + * `MediaResponseImpl`, the ClassCastException will be thrown. * - * @return The actual instance of `BatchMediaImpl` - * @throws ClassCastException if the instance is not `BatchMediaImpl` + * @return The actual instance of `MediaResponseImpl` + * @throws ClassCastException if the instance is not `MediaResponseImpl` */ - public BatchMediaImpl getBatchMediaImpl() throws ClassCastException { - return (BatchMediaImpl) super.getActualInstance(); + public MediaResponseImpl getMediaResponseImpl() throws ClassCastException { + return (MediaResponseImpl) super.getActualInstance(); } /** - * Get the actual instance of `BatchTextImpl`. If the actual instance is not `BatchTextImpl`, the - * ClassCastException will be thrown. + * Get the actual instance of `TextResponseImpl`. If the actual instance is not + * `TextResponseImpl`, the ClassCastException will be thrown. * - * @return The actual instance of `BatchTextImpl` - * @throws ClassCastException if the instance is not `BatchTextImpl` + * @return The actual instance of `TextResponseImpl` + * @throws ClassCastException if the instance is not `TextResponseImpl` */ - public BatchTextImpl getBatchTextImpl() throws ClassCastException { - return (BatchTextImpl) super.getActualInstance(); + public TextResponseImpl getTextResponseImpl() throws ClassCastException { + return (TextResponseImpl) super.getActualInstance(); } public static class Deserializer - extends StdDeserializer { + extends StdDeserializer { public Deserializer() { this(null); } - public Deserializer(Class vc) { + public Deserializer( + Class vc) { super(vc); } @Override - public com.sinch.sdk.domains.sms.models.v1.batches.response.Batch deserialize( + public com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse deserialize( JsonParser jp, DeserializationContext ctxt) throws IOException { Object deserialized = jp.readValueAs(BatchResponseInternalImpl.class).getActualInstance(); if (null == deserialized) { return null; } - if (!(deserialized instanceof com.sinch.sdk.domains.sms.models.v1.batches.response.Batch)) { + if (!(deserialized + instanceof com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse)) { log.log(Level.SEVERE, "Input data does not match schema ", deserialized); return null; } - return (com.sinch.sdk.domains.sms.models.v1.batches.response.Batch) deserialized; + return (com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse) deserialized; } } } From f065338bc722442f35e43079615561e13e241e73 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 14 Dec 2024 11:11:04 +0100 Subject: [PATCH 26/65] feat (SMS/Batches) Use class as query parameters --- .../domains/sms/api/v1/BatchesService.java | 7 +- .../sms/api/v1/adapters/BatchesService.java | 24 +-- .../batches/request/ListBatchesRequest.java | 141 ------------------ .../batches/response/ListBatchesResponse.java | 9 +- .../api/v1/adapters/BatchesServiceTest.java | 24 +-- .../v1/request/ListBatchesRequestTest.java | 57 ------- .../sdk/e2e/domains/sms/v1/BatchesSteps.java | 16 +- .../databind/QueryParameterSerializer.java | 5 + .../InstantToIso8601Serializer.java | 26 ++++ .../InstantToIso8601SerializerTest.java | 31 ++++ .../com/sinch/sample/sms/v1/batches/List.java | 8 +- .../sms/v1/batches/SendDeliveryFeedback.java | 2 +- .../sinch/sample/sms/v1/batches/dryRun.java | 7 +- 13 files changed, 116 insertions(+), 241 deletions(-) delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java delete mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java create mode 100644 core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java create mode 100644 core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java create mode 100644 core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index c83cbcec8..0d917bfb9 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -2,7 +2,8 @@ import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; @@ -13,9 +14,9 @@ public interface BatchesService { BatchResponse send(BatchRequest batch) throws ApiException; - ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException; + ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException; - DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch); + DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch); BatchResponse get(String batchId) throws ApiException; diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index b2d4d166b..e189c9484 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -8,7 +8,8 @@ import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; @@ -16,7 +17,6 @@ import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; import com.sinch.sdk.models.SmsContext; -import java.time.Instant; import java.util.Map; public class BatchesService implements com.sinch.sdk.domains.sms.api.v1.BatchesService { @@ -40,20 +40,12 @@ public BatchResponse send(BatchRequest batch) throws ApiException { return getApi().send(batch); } - public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiException { + public ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException { - ListBatchesRequest guardParameters = - null != parameters ? parameters : ListBatchesRequest.builder().build(); + ListBatchesQueryParameters guardParameters = + null != parameters ? parameters : ListBatchesQueryParameters.builder().build(); - ApiBatchList response = - getApi() - .list( - guardParameters.getPage().orElse(null), - guardParameters.getPageSize().orElse(null), - guardParameters.getFrom().orElse(null), - guardParameters.getStartDate().map(Instant::toString).orElse(null), - guardParameters.getEndDate().map(Instant::toString).orElse(null), - guardParameters.getClientReference().orElse(null)); + ApiBatchList response = getApi().list(parameters); SMSCursorPageNavigator navigator = new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); @@ -62,8 +54,8 @@ public ListBatchesResponse list(ListBatchesRequest parameters) throws ApiExcepti this, new Page<>(guardParameters, response.getBatches(), navigator)); } - public DryRunResponse dryRun(boolean perRecipient, int numberOfRecipient, BatchRequest batch) { - return getApi().dryRun(perRecipient, numberOfRecipient, batch); + public DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch) { + return getApi().dryRun(queryParameters, batch); } public BatchResponse get(String batchId) throws ApiException { diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java deleted file mode 100644 index b6415dd14..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesRequest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.sinch.sdk.domains.sms.models.v1.batches.request; - -import com.sinch.sdk.core.models.OptionalValue; -import java.time.Instant; - -public class ListBatchesRequest { - - private final OptionalValue from; - private final OptionalValue startDate; - private final OptionalValue endDate; - private final OptionalValue clientReference; - private final OptionalValue page; - private final OptionalValue pageSize; - - private ListBatchesRequest( - OptionalValue from, - OptionalValue startDate, - OptionalValue endDate, - OptionalValue clientReference, - OptionalValue page, - OptionalValue pageSize) { - this.from = from; - this.startDate = startDate; - this.endDate = endDate; - this.clientReference = clientReference; - this.page = page; - this.pageSize = pageSize; - } - - public OptionalValue getFrom() { - return from; - } - - public OptionalValue getStartDate() { - return startDate; - } - - public OptionalValue getEndDate() { - return endDate; - } - - public OptionalValue getClientReference() { - return clientReference; - } - - public OptionalValue getPage() { - return page; - } - - public OptionalValue getPageSize() { - return pageSize; - } - - public static Builder builder() { - return new Builder(); - } - - public static Builder builder(ListBatchesRequest parameters) { - return new Builder(parameters); - } - - public static class Builder { - - OptionalValue from = OptionalValue.empty(); - OptionalValue startDate = OptionalValue.empty(); - OptionalValue endDate = OptionalValue.empty(); - OptionalValue clientReference = OptionalValue.empty(); - OptionalValue page = OptionalValue.empty(); - OptionalValue pageSize = OptionalValue.empty(); - - private Builder() {} - - private Builder(ListBatchesRequest parameters) { - this.from = parameters.from; - this.startDate = parameters.startDate; - this.endDate = parameters.endDate; - this.clientReference = parameters.clientReference; - this.page = parameters.page; - this.pageSize = parameters.pageSize; - } - - /** - * @param from Only list messages sent from this sender number. Multiple originating numbers can - * be comma separated. Must be phone numbers or short code. - * @return current builder - */ - public Builder setFrom(String from) { - this.from = OptionalValue.of(from); - return this; - } - - /** - * @param startDate Only list messages received at or after this date/time. - * @return current builder - */ - public Builder setStartDate(Instant startDate) { - this.startDate = OptionalValue.of(startDate); - return this; - } - - /** - * @param endDate Only list messages received before this date/time - * @return current builder - */ - public Builder setEndDate(Instant endDate) { - this.endDate = OptionalValue.of(endDate); - return this; - } - - /** - * @param clientReference Client reference to include - * @return current builder - */ - public Builder setClientReference(String clientReference) { - this.clientReference = OptionalValue.of(clientReference); - return this; - } - - /** - * @param page The page number starting from 0 - * @return current builder - */ - public Builder setPage(Integer page) { - this.page = OptionalValue.of(page); - return this; - } - - /** - * @param pageSize Determines the size of a page - * @return current builder - */ - public Builder setPageSize(Integer pageSize) { - this.pageSize = OptionalValue.of(pageSize); - return this; - } - - public ListBatchesRequest build() { - return new ListBatchesRequest(from, startDate, endDate, clientReference, page, pageSize); - } - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java index 20a0ce6bd..02bd716fa 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java @@ -3,18 +3,18 @@ import com.sinch.sdk.core.models.pagination.ListResponse; import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.api.v1.BatchesService; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import java.util.Collection; import java.util.NoSuchElementException; public class ListBatchesResponse extends ListResponse { - private final Page page; + private final Page page; private final BatchesService service; private ListBatchesResponse nextPage; public ListBatchesResponse( - BatchesService service, Page page) { + BatchesService service, Page page) { this.service = service; this.page = page; } @@ -22,7 +22,8 @@ public ListBatchesResponse( public boolean hasNextPage() { if (null == nextPage) { - ListBatchesRequest.Builder newParameters = ListBatchesRequest.builder(page.getParameters()); + ListBatchesQueryParameters.Builder newParameters = + ListBatchesQueryParameters.builder(page.getParameters()); newParameters.setPage(page.getNextPageToken()); nextPage = service.list(newParameters.build()); } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java index 67189c06c..1cc3825c3 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java @@ -18,6 +18,8 @@ import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest; import com.sinch.sdk.domains.sms.models.v1.batches.request.BinaryRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.MediaRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; @@ -347,9 +349,12 @@ void sendText() throws ApiException { @Test void dryRun() throws ApiException { - when(api.dryRun(eq(true), eq(456), eq(sendSmsBatchTextRequest))).thenReturn(dryRunResponseDto); + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(456).build(); + when(api.dryRun(eq(queryParameters), eq(sendSmsBatchTextRequest))) + .thenReturn(dryRunResponseDto); - DryRunResponse response = service.dryRun(true, 456, sendSmsBatchTextRequest); + DryRunResponse response = service.dryRun(queryParameters, sendSmsBatchTextRequest); TestHelpers.recursiveEquals(response, dryRunResponseDto); } @@ -357,13 +362,14 @@ void dryRun() throws ApiException { @Test void list() throws ApiException { - when(api.list(eq(null), eq(null), eq(null), eq(null), eq(null), eq(null))) - .thenReturn(listBatchesResponseDtoPage0); - when(api.list(eq(1), eq(null), eq(null), eq(null), eq(null), eq(null))) - .thenReturn(listBatchesResponseDtoPage1); - when(api.list(eq(2), eq(null), eq(null), eq(null), eq(null), eq(null))) - .thenReturn(listBatchesResponseDtoPage2); - ListBatchesResponse response = service.list(null); + ListBatchesQueryParameters initialRequest = ListBatchesQueryParameters.builder().build(); + ListBatchesQueryParameters page1 = ListBatchesQueryParameters.builder().setPage(1).build(); + ListBatchesQueryParameters page2 = ListBatchesQueryParameters.builder().setPage(2).build(); + + when(api.list(initialRequest)).thenReturn(listBatchesResponseDtoPage0); + when(api.list(page1)).thenReturn(listBatchesResponseDtoPage1); + when(api.list(page2)).thenReturn(listBatchesResponseDtoPage2); + ListBatchesResponse response = service.list(initialRequest); Iterator iterator = response.iterator(); BatchResponse batch = iterator.next(); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java deleted file mode 100644 index 085a39e84..000000000 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/request/ListBatchesRequestTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.sinch.sdk.domains.sms.models.v1.request; - -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; -import java.time.Instant; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; - -class ListBatchesRequestTest { - - static final String from = "foo from"; - - static Instant startDate = Instant.now(); - static Instant endDate = Instant.now(); - static String clientReference = "a client reference"; - static Integer page = 1; - static Integer pageSize = 3; - - public static final ListBatchesRequest value = - ListBatchesRequest.builder() - .setFrom(from) - .setStartDate(startDate) - .setEndDate(endDate) - .setClientReference(clientReference) - .setPage(page) - .setPageSize(pageSize) - .build(); - - @Test - void getFrom() { - Assertions.assertThat(value.getFrom().get()).isEqualTo(from); - } - - @Test - void getStartDate() { - Assertions.assertThat(value.getStartDate().get()).isEqualTo(startDate); - } - - @Test - void getEndDate() { - Assertions.assertThat(value.getEndDate().get()).isEqualTo(endDate); - } - - @Test - void getClientReference() { - Assertions.assertThat(value.getClientReference().get()).isEqualTo(clientReference); - } - - @Test - void getPage() { - Assertions.assertThat(value.getPage().get()).isEqualTo(page); - } - - @Test - void getPageSize() { - Assertions.assertThat(value.getPageSize().get()).isEqualTo(pageSize); - } -} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java index 7d58a5f84..a73724315 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/BatchesSteps.java @@ -3,7 +3,8 @@ import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; @@ -117,26 +118,31 @@ public void dryRun() { .setDeliveryReport(DeliveryReportType.NONE) .build(); - dryRunResponse = service.dryRun(true, 3, request); + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(3).build(); + dryRunResponse = service.dryRun(queryParameters, request); } @When("^I send a request to list the SMS batches$") public void listOnePage() { - ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + ListBatchesQueryParameters request = + ListBatchesQueryParameters.builder().setPageSize(2).build(); listOnePageResponse = service.list(request); } @When("^I send a request to list all the SMS batches$") public void listAll() { - ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + ListBatchesQueryParameters request = + ListBatchesQueryParameters.builder().setPageSize(2).build(); listAllResponse = service.list(request); } @When("^I iterate manually over the SMS batches pages$") public void listAllByPage() { - ListBatchesRequest request = ListBatchesRequest.builder().setPageSize(2).build(); + ListBatchesQueryParameters request = + ListBatchesQueryParameters.builder().setPageSize(2).build(); listAllByPageResponse = service.list(request); } diff --git a/core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java b/core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java new file mode 100644 index 000000000..9b049d1f6 --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/databind/QueryParameterSerializer.java @@ -0,0 +1,5 @@ +package com.sinch.sdk.core.databind; + +import java.util.function.Function; + +public interface QueryParameterSerializer extends Function {} diff --git a/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java b/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java new file mode 100644 index 000000000..1381407a5 --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java @@ -0,0 +1,26 @@ +package com.sinch.sdk.core.databind.query_parameter; + +import com.sinch.sdk.core.databind.QueryParameterSerializer; +import java.time.Instant; + +public class InstantToIso8601Serializer implements QueryParameterSerializer { + + public static InstantToIso8601Serializer getInstance() { + return LazyHolder.INSTANCE; + } + + @Override + public String apply(Instant instant) { + if (null == instant) { + return null; + } + return instant.toString(); + } + + private static class LazyHolder { + private static final InstantToIso8601Serializer INSTANCE = new InstantToIso8601Serializer(); + } + + private InstantToIso8601Serializer() {} + ; +} diff --git a/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java new file mode 100644 index 000000000..430eedfb9 --- /dev/null +++ b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java @@ -0,0 +1,31 @@ +package com.sinch.sdk.core.databind.query_parameter; + +import static org.junit.jupiter.api.Assertions.*; + +import com.sinch.sdk.core.TestHelpers; +import java.time.Instant; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class InstantToIso8601SerializerTest { + + InstantToIso8601Serializer serializer = InstantToIso8601Serializer.getInstance(); + + @Test + void serialize() { + + Instant instant = Instant.parse("2024-05-04T10:00:00.123Z"); + + String serialized = serializer.apply(instant); + + TestHelpers.recursiveEquals("2024-05-04T10:00:00.123Z", serialized); + } + + @Test + void serializeNull() { + + String serialized = serializer.apply(null); + + Assertions.assertNull(serialized); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java index 6ee193456..132f66fc3 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/List.java @@ -2,8 +2,10 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import java.io.IOException; +import java.time.Instant; +import java.time.Period; import java.util.logging.Logger; public class List extends BaseApplication { @@ -29,12 +31,12 @@ public void run() { LOGGER.info("Response:"); service .list( - ListBatchesRequest.builder() + ListBatchesQueryParameters.builder() // .setFrom(phoneNumber) // .setPage(15) .setPageSize(2) // .setClientReference("a client reference") - // .setStartDate(Instant.now()) + .setStartDate(Instant.now().minus(Period.ofWeeks(3))) .build()) .iterator() .forEachRemaining(f -> LOGGER.info(f.toString())); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java index ab89da20e..7ea8acb24 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java @@ -30,7 +30,7 @@ public void run() { SendDeliveryFeedbackRequest request = SendDeliveryFeedbackRequest.builder() - .setRecipients(Arrays.asList("foo number 1", "foo number 2")) + .setRecipients(Arrays.asList("+1234567890", "+0987654321")) .build(); service.sendDeliveryFeedback(batchId, request); LOGGER.info("Done"); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java index 7fd0c48be..7a529a33d 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/dryRun.java @@ -2,6 +2,7 @@ import com.sinch.sample.BaseApplication; import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import java.io.IOException; @@ -28,10 +29,12 @@ public void run() { BatchesService service = client.sms().v1().batches(); LOGGER.info("DryRun Request"); + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(3).build(); + DryRunResponse value = service.dryRun( - true, - 3, + queryParameters, TextRequest.builder() .setTo(Collections.singletonList(phoneNumber)) .setBody("the body") From 261f813f52fe6542ccf0457e8b2440186a407983 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 16 Dec 2024 16:20:00 +0100 Subject: [PATCH 27/65] feat (SMS/Batches) Generated files --- .../sms/api/v1/internal/BatchesApi.java | 250 +++++++----------- .../request/DryRunQueryParameters.java | 78 ++++++ .../request/DryRunQueryParametersImpl.java | 90 +++++++ .../request/ListBatchesQueryParameters.java | 143 ++++++++++ .../ListBatchesQueryParametersImpl.java | 157 +++++++++++ 5 files changed, 569 insertions(+), 149 deletions(-) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java index 608bb175d..569ff6c58 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java @@ -11,6 +11,7 @@ package com.sinch.sdk.domains.sms.api.v1.internal; import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; import com.sinch.sdk.core.http.AuthManager; @@ -24,6 +25,8 @@ import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; @@ -74,14 +77,7 @@ public BatchesApi( */ public BatchResponse cancel(String batchId) throws ApiException { - LOGGER.finest( - "[cancel]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "batchId: " - + batchId); + LOGGER.finest("[cancel]" + " " + "batchId: " + batchId); HttpRequest httpRequest = cancelRequestBuilder(batchId); HttpResponse response = @@ -146,33 +142,24 @@ private HttpRequest cancelRequestBuilder(String batchId) throws ApiException { * Dry run This operation will perform a dry run of a batch which calculates the bodies and number * of parts for all messages in the batch without actually sending any messages. * - * @param perRecipient Whether to include per recipient details in the response (optional) - * @param numberOfRecipients Max number of recipients to include per recipient details for in the - * response (optional, default to 100) + * @param queryParameter (optional) * @param sendRequest (optional) * @return DryRunResponse * @throws ApiException if fails to make API call */ - public DryRunResponse dryRun( - Boolean perRecipient, Integer numberOfRecipients, BatchRequest sendRequest) + public DryRunResponse dryRun(DryRunQueryParameters queryParameter, BatchRequest sendRequest) throws ApiException { LOGGER.finest( "[dryRun]" + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "perRecipient: " - + perRecipient - + ", " - + "numberOfRecipients: " - + numberOfRecipients + + "queryParameter: " + + queryParameter + ", " + "sendRequest: " + sendRequest); - HttpRequest httpRequest = dryRunRequestBuilder(perRecipient, numberOfRecipients, sendRequest); + HttpRequest httpRequest = dryRunRequestBuilder(queryParameter, sendRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -191,8 +178,7 @@ public DryRunResponse dryRun( } private HttpRequest dryRunRequestBuilder( - Boolean perRecipient, Integer numberOfRecipients, BatchRequest sendRequest) - throws ApiException { + DryRunQueryParameters queryParameter, BatchRequest sendRequest) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( @@ -206,22 +192,30 @@ private HttpRequest dryRunRequestBuilder( URLPathUtils.encodePathSegment(this.servicePlanId.toString())); List localVarQueryParams = new ArrayList<>(); - if (null != perRecipient) { - localVarQueryParams.add( - new URLParameter( - "per_recipient", - perRecipient, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true)); - } - if (null != numberOfRecipients) { - localVarQueryParams.add( - new URLParameter( - "number_of_recipients", - numberOfRecipients, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true)); - } + DryRunQueryParameters guardParameters = + null != queryParameter ? queryParameter : DryRunQueryParameters.builder().build(); + + guardParameters + .getPerRecipient() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "per_recipient", + g, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true))); + + guardParameters + .getNumberOfRecipients() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "number_of_recipients", + g, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true))); Map localVarHeaderParams = new HashMap<>(); @@ -252,8 +246,7 @@ private HttpRequest dryRunRequestBuilder( */ public BatchResponse get(String batchId) throws ApiException { - LOGGER.finest( - "[get]" + " " + "this.servicePlanId: " + this.servicePlanId + ", " + "batchId: " + batchId); + LOGGER.finest("[get]" + " " + "batchId: " + batchId); HttpRequest httpRequest = getRequestBuilder(batchId); HttpResponse response = @@ -318,55 +311,15 @@ private HttpRequest getRequestBuilder(String batchId) throws ApiException { * List Batches With the list operation you can list batch messages created in the last 14 days * that you have created. This operation supports pagination. * - * @param page The page number starting from 0. (optional, default to 0) - * @param pageSize Determines the size of a page. (optional, default to 30) - * @param from Only list messages sent from this sender number. Multiple originating numbers can - * be comma separated. Must be phone numbers or short code. (optional) - * @param startDate Only list messages received at or after this date/time. Formatted as - * [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. - * Default: Now-24 (optional) - * @param endDate Only list messages received before this date/time. Formatted as - * [ISO-8601](https://en.wikipedia.org/wiki/ISO_8601): `YYYY-MM-DDThh:mm:ss.SSSZ`. - * (optional) - * @param clientReference Client reference to include (optional) + * @param queryParameter (optional) * @return ApiBatchList * @throws ApiException if fails to make API call */ - public ApiBatchList list( - Integer page, - Integer pageSize, - String from, - String startDate, - String endDate, - String clientReference) - throws ApiException { + public ApiBatchList list(ListBatchesQueryParameters queryParameter) throws ApiException { - LOGGER.finest( - "[list]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "page: " - + page - + ", " - + "pageSize: " - + pageSize - + ", " - + "from: " - + from - + ", " - + "startDate: " - + startDate - + ", " - + "endDate: " - + endDate - + ", " - + "clientReference: " - + clientReference); + LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); - HttpRequest httpRequest = - listRequestBuilder(page, pageSize, from, startDate, endDate, clientReference); + HttpRequest httpRequest = listRequestBuilder(queryParameter); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -384,13 +337,7 @@ public ApiBatchList list( mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest listRequestBuilder( - Integer page, - Integer pageSize, - String from, - String startDate, - String endDate, - String clientReference) + private HttpRequest listRequestBuilder(ListBatchesQueryParameters queryParameter) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { @@ -405,37 +352,65 @@ private HttpRequest listRequestBuilder( URLPathUtils.encodePathSegment(this.servicePlanId.toString())); List localVarQueryParams = new ArrayList<>(); - if (null != page) { - localVarQueryParams.add( - new URLParameter("page", page, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != pageSize) { - localVarQueryParams.add( - new URLParameter( - "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != from) { - localVarQueryParams.add( - new URLParameter("from", from, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != startDate) { - localVarQueryParams.add( - new URLParameter( - "start_date", startDate, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != endDate) { - localVarQueryParams.add( - new URLParameter( - "end_date", endDate, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); - } - if (null != clientReference) { - localVarQueryParams.add( - new URLParameter( - "client_reference", - clientReference, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true)); - } + ListBatchesQueryParameters guardParameters = + null != queryParameter ? queryParameter : ListBatchesQueryParameters.builder().build(); + + guardParameters + .getPage() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "page", g, URLParameter.STYLE.valueOf("form".toUpperCase()), true))); + + guardParameters + .getPageSize() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "page_size", g, URLParameter.STYLE.valueOf("form".toUpperCase()), true))); + + guardParameters + .getFrom() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "from", g, URLParameter.STYLE.valueOf("form".toUpperCase()), true))); + + guardParameters + .getStartDate() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "start_date", + InstantToIso8601Serializer.getInstance().apply(g), + URLParameter.STYLE.valueOf("form".toUpperCase()), + true))); + + guardParameters + .getEndDate() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "end_date", + InstantToIso8601Serializer.getInstance().apply(g), + URLParameter.STYLE.valueOf("form".toUpperCase()), + true))); + + guardParameters + .getClientReference() + .ifPresent( + g -> + localVarQueryParams.add( + new URLParameter( + "client_reference", + g, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true))); Map localVarHeaderParams = new HashMap<>(); @@ -468,17 +443,7 @@ private HttpRequest listRequestBuilder( */ public BatchResponse replace(String batchId, BatchRequest sendRequest) throws ApiException { - LOGGER.finest( - "[replace]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "batchId: " - + batchId - + ", " - + "sendRequest: " - + sendRequest); + LOGGER.finest("[replace]" + " " + "batchId: " + batchId + ", " + "sendRequest: " + sendRequest); HttpRequest httpRequest = replaceRequestBuilder(batchId, sendRequest); HttpResponse response = @@ -561,9 +526,6 @@ public void sendDeliveryFeedback( LOGGER.finest( "[sendDeliveryFeedback]" + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " + "batchId: " + batchId + ", " @@ -653,14 +615,7 @@ private HttpRequest sendDeliveryFeedbackRequestBuilder( */ public BatchResponse send(BatchRequest sendRequest) throws ApiException { - LOGGER.finest( - "[send]" - + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " - + "sendRequest: " - + sendRequest); + LOGGER.finest("[send]" + " " + "sendRequest: " + sendRequest); HttpRequest httpRequest = sendRequestBuilder(sendRequest); HttpResponse response = @@ -730,9 +685,6 @@ public BatchResponse update(String batchId, UpdateBatchRequest updateBatchReques LOGGER.finest( "[update]" + " " - + "this.servicePlanId: " - + this.servicePlanId - + ", " + "batchId: " + batchId + ", " diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java new file mode 100644 index 000000000..2bc16fc1f --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParameters.java @@ -0,0 +1,78 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; + +/** DryRunQueryParameters */ +public interface DryRunQueryParameters { + + /** + * Get perRecipient + * + * @return perRecipient + */ + OptionalValue getPerRecipient(); + + /** + * Get numberOfRecipients maximum: 1000 + * + * @return numberOfRecipients + */ + OptionalValue getNumberOfRecipients(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new DryRunQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(DryRunQueryParameters parameters) { + return new DryRunQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param perRecipient see getter + * @return Current builder + * @see #getPerRecipient + */ + Builder setPerRecipient(Boolean perRecipient); + + /** + * see getter + * + * @param numberOfRecipients see getter + * @return Current builder + * @see #getNumberOfRecipients + */ + Builder setNumberOfRecipients(Integer numberOfRecipients); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + DryRunQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java new file mode 100644 index 000000000..a5d2201cd --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java @@ -0,0 +1,90 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +public class DryRunQueryParametersImpl implements DryRunQueryParameters { + + private final OptionalValue perRecipient; + private final OptionalValue numberOfRecipients; + + private DryRunQueryParametersImpl( + OptionalValue perRecipient, OptionalValue numberOfRecipients) { + this.perRecipient = perRecipient; + this.numberOfRecipients = numberOfRecipients; + } + + public OptionalValue getPerRecipient() { + return perRecipient; + } + + public OptionalValue getNumberOfRecipients() { + return numberOfRecipients; + } + + /** Return true if this DryRunQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DryRunQueryParametersImpl dryRunQueryParameters = (DryRunQueryParametersImpl) o; + return Objects.equals(this.perRecipient, dryRunQueryParameters.perRecipient) + && Objects.equals(this.numberOfRecipients, dryRunQueryParameters.numberOfRecipients); + } + + @Override + public int hashCode() { + return Objects.hash(perRecipient, numberOfRecipients); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DryRunQueryParametersImpl {\n"); + sb.append(" perRecipient: ").append(toIndentedString(perRecipient)).append("\n"); + sb.append(" numberOfRecipients: ").append(toIndentedString(numberOfRecipients)).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 "); + } + + static class Builder implements DryRunQueryParameters.Builder { + OptionalValue perRecipient = OptionalValue.empty(); + OptionalValue numberOfRecipients = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(DryRunQueryParameters _parameters) { + DryRunQueryParametersImpl parameters = (DryRunQueryParametersImpl) _parameters; + this.perRecipient = parameters.getPerRecipient(); + this.numberOfRecipients = parameters.getNumberOfRecipients(); + } + + public Builder setPerRecipient(Boolean perRecipient) { + this.perRecipient = OptionalValue.of(perRecipient); + return this; + } + + public Builder setNumberOfRecipients(Integer numberOfRecipients) { + this.numberOfRecipients = OptionalValue.of(numberOfRecipients); + return this; + } + + public DryRunQueryParameters build() { + return new DryRunQueryParametersImpl(perRecipient, numberOfRecipients); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java new file mode 100644 index 000000000..d2032cd22 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParameters.java @@ -0,0 +1,143 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; + +/** ListBatchesQueryParameters */ +public interface ListBatchesQueryParameters { + + /** + * Get page minimum: 0 + * + * @return page + */ + OptionalValue getPage(); + + /** + * Get pageSize maximum: 100 + * + * @return pageSize + */ + OptionalValue getPageSize(); + + /** + * Get from + * + * @return from + */ + OptionalValue getFrom(); + + /** + * Get startDate + * + * @return startDate + */ + OptionalValue getStartDate(); + + /** + * Get endDate + * + * @return endDate + */ + OptionalValue getEndDate(); + + /** + * Get clientReference + * + * @return clientReference + */ + OptionalValue getClientReference(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ListBatchesQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(ListBatchesQueryParameters parameters) { + return new ListBatchesQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param startDate see getter + * @return Current builder + * @see #getStartDate + */ + Builder setStartDate(Instant startDate); + + /** + * see getter + * + * @param endDate see getter + * @return Current builder + * @see #getEndDate + */ + Builder setEndDate(Instant endDate); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ListBatchesQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java new file mode 100644 index 000000000..8372d2cca --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java @@ -0,0 +1,157 @@ +package com.sinch.sdk.domains.sms.models.v1.batches.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Objects; + +public class ListBatchesQueryParametersImpl implements ListBatchesQueryParameters { + + private final OptionalValue page; + private final OptionalValue pageSize; + private final OptionalValue from; + private final OptionalValue startDate; + private final OptionalValue endDate; + private final OptionalValue clientReference; + + private ListBatchesQueryParametersImpl( + OptionalValue page, + OptionalValue pageSize, + OptionalValue from, + OptionalValue startDate, + OptionalValue endDate, + OptionalValue clientReference) { + this.page = page; + this.pageSize = pageSize; + this.from = from; + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + } + + public OptionalValue getPage() { + return page; + } + + public OptionalValue getPageSize() { + return pageSize; + } + + public OptionalValue getFrom() { + return from; + } + + public OptionalValue getStartDate() { + return startDate; + } + + public OptionalValue getEndDate() { + return endDate; + } + + public OptionalValue getClientReference() { + return clientReference; + } + + /** Return true if this ListBatchesQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ListBatchesQueryParametersImpl listBatchesQueryParameters = (ListBatchesQueryParametersImpl) o; + return Objects.equals(this.page, listBatchesQueryParameters.page) + && Objects.equals(this.pageSize, listBatchesQueryParameters.pageSize) + && Objects.equals(this.from, listBatchesQueryParameters.from) + && Objects.equals(this.startDate, listBatchesQueryParameters.startDate) + && Objects.equals(this.endDate, listBatchesQueryParameters.endDate) + && Objects.equals(this.clientReference, listBatchesQueryParameters.clientReference); + } + + @Override + public int hashCode() { + return Objects.hash(page, pageSize, from, startDate, endDate, clientReference); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ListBatchesQueryParametersImpl {\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" startDate: ").append(toIndentedString(startDate)).append("\n"); + sb.append(" endDate: ").append(toIndentedString(endDate)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).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 "); + } + + static class Builder implements ListBatchesQueryParameters.Builder { + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue startDate = OptionalValue.empty(); + OptionalValue endDate = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(ListBatchesQueryParameters _parameters) { + ListBatchesQueryParametersImpl parameters = (ListBatchesQueryParametersImpl) _parameters; + this.page = parameters.getPage(); + this.pageSize = parameters.getPageSize(); + this.from = parameters.getFrom(); + this.startDate = parameters.getStartDate(); + this.endDate = parameters.getEndDate(); + this.clientReference = parameters.getClientReference(); + } + + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = OptionalValue.of(startDate); + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = OptionalValue.of(endDate); + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + public ListBatchesQueryParameters build() { + return new ListBatchesQueryParametersImpl( + page, pageSize, from, startDate, endDate, clientReference); + } + } +} From 5341c9e87199d10ab344f4322904b96114fbeaf0 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 19:44:34 +0100 Subject: [PATCH 28/65] feat (core): Provide URLParameter helper to add a query param to a list --- .../com/sinch/sdk/core/http/URLParameter.java | 13 ++++- .../sdk/core/http/URLParameterUtils.java | 25 ++++++++- .../InstantToIso8601SerializerTest.java | 2 - .../sinch/sdk/core/http/URLParameterTest.java | 44 +++++++++++++++ .../sdk/core/http/URLParameterUtilsTest.java | 55 +++++++++++++++++++ 5 files changed, 134 insertions(+), 5 deletions(-) create mode 100644 core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameter.java b/core/src/main/com/sinch/sdk/core/http/URLParameter.java index 82a54171f..c84d4c2b9 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameter.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameter.java @@ -69,6 +69,17 @@ public enum STYLE { SIMPLE, SPACE_DELIMITED, PIPE_DELIMITED, - DEEP_OBJECT + DEEP_OBJECT; } + + // the following constants do not follow java standard by purpose + // Aim is to have direct access to OpenApi Spec authorized values as constant without overhead + // ref: https://spec.openapis.org/oas/latest.html#style-values + public static final STYLE matrix = STYLE.MATRIX; + public static final STYLE label = STYLE.LABEL; + public static final STYLE form = STYLE.FORM; + public static final STYLE simple = STYLE.SIMPLE; + public static final STYLE spaceDelimited = STYLE.SPACE_DELIMITED; + public static final STYLE pipeDelimited = STYLE.PIPE_DELIMITED; + public static final STYLE deepObject = STYLE.DEEP_OBJECT; } diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java index 7ced9d8b9..6def5f845 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameterUtils.java @@ -1,6 +1,9 @@ package com.sinch.sdk.core.http; +import com.sinch.sdk.core.databind.QueryParameterSerializer; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.core.utils.EnumDynamic; import com.sinch.sdk.core.utils.StringUtil; import java.io.UnsupportedEncodingException; @@ -8,6 +11,7 @@ import java.security.InvalidParameterException; import java.util.Arrays; import java.util.Collection; +import java.util.List; import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -26,7 +30,7 @@ public static String encodeParametersAsString(Collection parameter .collect(Collectors.joining("&")); } - public static Optional encode(URLParameter parameter) { + protected static Optional encode(URLParameter parameter) { if (null == parameter || StringUtil.isEmpty(parameter.getName()) @@ -195,7 +199,7 @@ private static Optional encodeObject(URLParameter parameter) { throw new ApiException("Not yet implemented '" + parameter + "'"); } - public static String encodeParameterValue(String value) { + private static String encodeParameterValue(String value) { try { return URLEncoder.encode(value, "UTF-8").replaceAll("\\.", "%2E"); @@ -203,4 +207,21 @@ public static String encodeParameterValue(String value) { return value; } } + + public static void addQueryParam( + OptionalValue optionalValue, + String paramName, + STYLE paramStyle, + QueryParameterSerializer serializer, + List queryParametersList, + boolean explode) { + optionalValue.ifPresent( + value -> + queryParametersList.add( + new URLParameter( + paramName, + null == serializer ? value : serializer.apply(value), + paramStyle, + explode))); + } } diff --git a/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java index 430eedfb9..2806c58a1 100644 --- a/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java +++ b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601SerializerTest.java @@ -1,7 +1,5 @@ package com.sinch.sdk.core.databind.query_parameter; -import static org.junit.jupiter.api.Assertions.*; - import com.sinch.sdk.core.TestHelpers; import java.time.Instant; import org.junit.jupiter.api.Assertions; diff --git a/core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java b/core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java new file mode 100644 index 000000000..f39bcf295 --- /dev/null +++ b/core/src/test/java/com/sinch/sdk/core/http/URLParameterTest.java @@ -0,0 +1,44 @@ +package com.sinch.sdk.core.http; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.sinch.sdk.core.http.URLParameter.STYLE; +import org.junit.jupiter.api.Test; + +class URLParameterTest { + + @Test + void matrix() { + assertEquals(STYLE.MATRIX, URLParameter.matrix); + } + + @Test + void label() { + assertEquals(STYLE.LABEL, URLParameter.label); + } + + @Test + void form() { + assertEquals(STYLE.FORM, URLParameter.form); + } + + @Test + void simple() { + assertEquals(STYLE.SIMPLE, URLParameter.simple); + } + + @Test + void spaceDelimited() { + assertEquals(STYLE.SPACE_DELIMITED, URLParameter.spaceDelimited); + } + + @Test + void pipeDelimited() { + assertEquals(STYLE.PIPE_DELIMITED, URLParameter.pipeDelimited); + } + + @Test + void deepObject() { + assertEquals(STYLE.DEEP_OBJECT, URLParameter.deepObject); + } +} diff --git a/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java b/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java index 35b582384..0d977de46 100644 --- a/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java +++ b/core/src/test/java/com/sinch/sdk/core/http/URLParameterUtilsTest.java @@ -1,10 +1,18 @@ package com.sinch.sdk.core.http; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Optional; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -374,4 +382,51 @@ void encodePipeDelimitedArrayExplode() { URLParameter.STYLE.PIPE_DELIMITED, true))); } + + @Test + void addQueryParamNotPresent() { + + // Collections.emptyList() is not modifiable and will throw an exception if trying to add an + // entry + assertDoesNotThrow( + () -> + URLParameterUtils.addQueryParam( + OptionalValue.empty(), + "foo name", + STYLE.DEEP_OBJECT, + null, + Collections.emptyList(), + false), + "Ignored empty value"); + } + + @Test + void addQueryParamInteger() { + ArrayList list = new ArrayList<>(); + + URLParameterUtils.addQueryParam( + OptionalValue.of(15), "foo name", STYLE.DEEP_OBJECT, null, list, true); + assertEquals(1, list.size()); + + TestHelpers.recursiveEquals( + list.get(0), new URLParameter("foo name", 15, STYLE.DEEP_OBJECT, true)); + } + + @Test + void addQueryParamInstant() { + ArrayList list = new ArrayList<>(); + + URLParameterUtils.addQueryParam( + OptionalValue.of(Instant.parse("2024-05-04T10:00:00.123Z")), + "foo name", + STYLE.DEEP_OBJECT, + InstantToIso8601Serializer.getInstance(), + list, + true); + assertEquals(1, list.size()); + + TestHelpers.recursiveEquals( + list.get(0), + new URLParameter("foo name", "2024-05-04T10:00:00.123Z", STYLE.DEEP_OBJECT, true)); + } } From ad79ce423f95080e053323e7a83e8b952476d9a0 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 17 Dec 2024 19:45:30 +0100 Subject: [PATCH 29/65] refactor (SMS/Batches): Generated files --- .../sms/api/v1/internal/BatchesApi.java | 142 ++++++++---------- 1 file changed, 59 insertions(+), 83 deletions(-) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java index 569ff6c58..dfd0e385d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java @@ -22,6 +22,7 @@ import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.core.http.HttpStatus; import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; @@ -192,30 +193,24 @@ private HttpRequest dryRunRequestBuilder( URLPathUtils.encodePathSegment(this.servicePlanId.toString())); List localVarQueryParams = new ArrayList<>(); - DryRunQueryParameters guardParameters = - null != queryParameter ? queryParameter : DryRunQueryParameters.builder().build(); - - guardParameters - .getPerRecipient() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "per_recipient", - g, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true))); - - guardParameters - .getNumberOfRecipients() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "number_of_recipients", - g, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true))); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPerRecipient(), + "per_recipient", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getNumberOfRecipients(), + "number_of_recipients", + URLParameter.form, + null, + localVarQueryParams, + true); + } Map localVarHeaderParams = new HashMap<>(); @@ -352,65 +347,46 @@ private HttpRequest listRequestBuilder(ListBatchesQueryParameters queryParameter URLPathUtils.encodePathSegment(this.servicePlanId.toString())); List localVarQueryParams = new ArrayList<>(); - ListBatchesQueryParameters guardParameters = - null != queryParameter ? queryParameter : ListBatchesQueryParameters.builder().build(); - - guardParameters - .getPage() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "page", g, URLParameter.STYLE.valueOf("form".toUpperCase()), true))); - - guardParameters - .getPageSize() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "page_size", g, URLParameter.STYLE.valueOf("form".toUpperCase()), true))); - - guardParameters - .getFrom() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "from", g, URLParameter.STYLE.valueOf("form".toUpperCase()), true))); - - guardParameters - .getStartDate() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "start_date", - InstantToIso8601Serializer.getInstance().apply(g), - URLParameter.STYLE.valueOf("form".toUpperCase()), - true))); - - guardParameters - .getEndDate() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "end_date", - InstantToIso8601Serializer.getInstance().apply(g), - URLParameter.STYLE.valueOf("form".toUpperCase()), - true))); - - guardParameters - .getClientReference() - .ifPresent( - g -> - localVarQueryParams.add( - new URLParameter( - "client_reference", - g, - URLParameter.STYLE.valueOf("form".toUpperCase()), - true))); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPage(), "page", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getPageSize(), + "page_size", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getFrom(), "from", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getStartDate(), + "start_date", + URLParameter.form, + InstantToIso8601Serializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getEndDate(), + "end_date", + URLParameter.form, + InstantToIso8601Serializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getClientReference(), + "client_reference", + URLParameter.form, + null, + localVarQueryParams, + true); + } Map localVarHeaderParams = new HashMap<>(); From 55a8c2138d858a13c5355b26930ee5691c277a76 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 18 Dec 2024 10:07:41 +0100 Subject: [PATCH 30/65] test (SMS/Batches): Adding batches API calls regression tests --- .../sms/api/v1/internal/BatchesApiTest.java | 332 ++++++++++++++++++ .../com/sinch/sdk/core/http/URLParameter.java | 22 ++ .../sinch/sdk/core/http/HttpRequestTest.java | 22 ++ 3 files changed, 376 insertions(+) create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java create mode 100644 core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java new file mode 100644 index 000000000..c486d30c8 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java @@ -0,0 +1,332 @@ +package com.sinch.sdk.domains.sms.api.v1.internal; + +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +@TestWithResources +public class BatchesApiTest extends BaseTest { + + static final String SMS_AUTH_NAMES = "BearerAuth"; + + @GivenJsonResource("/domains/sms/v1/batches/request/TextRequestDto.json") + TextRequest textRequestDto; + + @GivenTextResource("/domains/sms/v1/batches/response/TextResponseDto.json") + String jsonTextResponseDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") + BatchResponse textResponseDto; + + @GivenTextResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") + String jsonDryRunResponseDto; + + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") + DryRunResponse dryRunResponseDto; + + @GivenTextResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") + String jsonBatchesResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") + ApiBatchList listBatchesResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/batches/request/UpdateTextRequestDto.json") + UpdateTextRequest updateTextRequestDto; + + @GivenJsonResource("/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json") + SendDeliveryFeedbackRequest sendDeliveryFeedbackRequestDto; + + @Mock HttpClient httpClient; + @Mock ServerConfiguration serverConfiguration; + + HttpMapper httpMapper = new HttpMapper(); + @Mock Map authManagers; + BatchesApi api; + String uriPartID = "foovalue"; + + @BeforeEach + public void initMocks() { + api = spy(new BatchesApi(httpClient, serverConfiguration, authManagers, httpMapper, uriPartID)); + } + + @Test + void get() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20binary%20batch%20id", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = api.get("foo binary batch id"); + + TestHelpers.recursiveEquals(response, textResponseDto); + } + + @Test + void send() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.POST, + Collections.emptyList(), + httpMapper.serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = api.send(textRequestDto); + + TestHelpers.recursiveEquals(response, textResponseDto); + } + + @Test + void dryRun() throws ApiException { + + DryRunQueryParameters queryParameters = + DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(456).build(); + + Collection urlParameters = + Arrays.asList( + new URLParameter("per_recipient", true, STYLE.FORM, true), + new URLParameter("number_of_recipients", 456, STYLE.FORM, true)); + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/dry_run", + HttpMethod.POST, + urlParameters, + httpMapper.serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonDryRunResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + DryRunResponse response = api.dryRun(queryParameters, textRequestDto); + + TestHelpers.recursiveEquals(response, dryRunResponseDto); + } + + @Test + void list() throws ApiException { + + Collection urlParameters = + Arrays.asList( + new URLParameter("page", 1, STYLE.FORM, true), + new URLParameter("page_size", 2, STYLE.FORM, true), + new URLParameter("from", "+1234567890", STYLE.FORM, true), + new URLParameter("start_date", "2023-11-03T15:21:21.113Z", STYLE.FORM, true), + new URLParameter("end_date", "2023-12-12T15:54:21.321Z", STYLE.FORM, true), + new URLParameter("client_reference", "client reference", STYLE.FORM, true)); + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.GET, + urlParameters, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonBatchesResponseDtoPage0.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + ListBatchesQueryParameters initialRequest = + ListBatchesQueryParameters.builder() + .setPage(1) + .setPageSize(2) + .setFrom("+1234567890") + .setClientReference("client reference") + .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) + .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) + .build(); + + ApiBatchList response = api.list(initialRequest); + + TestHelpers.recursiveEquals(response, listBatchesResponseDtoPage0); + } + + @Test + void update() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + HttpMethod.POST, + Collections.emptyList(), + httpMapper.serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), updateTextRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = api.update("foo text batch id", updateTextRequestDto); + + TestHelpers.recursiveEquals(response, textResponseDto); + } + + @Test + void replace() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + HttpMethod.PUT, + Collections.emptyList(), + httpMapper.serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = api.replace("foo text batch id", textRequestDto); + + TestHelpers.recursiveEquals(response, textResponseDto); + } + + @Test + void cancel() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + HttpMethod.DELETE, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = api.cancel("foo text batch id"); + + TestHelpers.recursiveEquals(response, textResponseDto); + } + + @Test + void sendDeliveryFeedback() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id/delivery_feedback", + HttpMethod.POST, + Collections.emptyList(), + httpMapper.serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), + sendDeliveryFeedbackRequestDto), + Collections.emptyMap(), + Collections.emptyList(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + api.sendDeliveryFeedback("foo text batch id", sendDeliveryFeedbackRequestDto); + } +} diff --git a/core/src/main/com/sinch/sdk/core/http/URLParameter.java b/core/src/main/com/sinch/sdk/core/http/URLParameter.java index c84d4c2b9..dd44c9546 100644 --- a/core/src/main/com/sinch/sdk/core/http/URLParameter.java +++ b/core/src/main/com/sinch/sdk/core/http/URLParameter.java @@ -1,5 +1,7 @@ package com.sinch.sdk.core.http; +import java.util.Objects; + public class URLParameter { private final String name; private final Object value; @@ -62,6 +64,26 @@ public String toString() { + '}'; } + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof URLParameter)) { + return false; + } + URLParameter that = (URLParameter) o; + return isExplode() == that.isExplode() + && Objects.equals(getName(), that.getName()) + && Objects.equals(getValue(), that.getValue()) + && getStyle() == that.getStyle(); + } + + @Override + public int hashCode() { + return Objects.hash(getName(), getValue(), getStyle(), isExplode()); + } + public enum STYLE { MATRIX, LABEL, diff --git a/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java b/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java new file mode 100644 index 000000000..212c4c765 --- /dev/null +++ b/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java @@ -0,0 +1,22 @@ +package com.sinch.sdk.core.http; + +import com.sinch.sdk.core.TestHelpers; +import org.mockito.ArgumentMatcher; + +public class HttpRequestTest { + + public static class HttpRequestMatcher implements ArgumentMatcher { + + private final HttpRequest left; + + public HttpRequestMatcher(HttpRequest left) { + this.left = left; + } + + @Override + public boolean matches(HttpRequest right) { + TestHelpers.recursiveEquals(right, left); + return true; + } + } +} From cce5d7811c1b8244f16f444dc36f6bf6dd93dd55 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 19 Dec 2024 09:16:24 +0100 Subject: [PATCH 31/65] feat (SMS/Inbounds) Generated files --- .../sms/api/v1/internal/InboundsApi.java | 246 +++++++++++ .../request/DryRunQueryParametersImpl.java | 3 + .../ListBatchesQueryParametersImpl.java | 3 + .../sms/models/v1/inbounds/BinaryMessage.java | 220 ++++++++++ .../models/v1/inbounds/BinaryMessageImpl.java | 332 +++++++++++++++ .../sms/models/v1/inbounds/MediaMessage.java | 204 +++++++++ .../models/v1/inbounds/MediaMessageBody.java | 87 ++++ .../v1/inbounds/MediaMessageBodyDetails.java | 102 +++++ .../inbounds/MediaMessageBodyDetailsImpl.java | 174 ++++++++ .../v1/inbounds/MediaMessageBodyImpl.java | 148 +++++++ .../models/v1/inbounds/MediaMessageImpl.java | 304 ++++++++++++++ .../sms/models/v1/inbounds/TextMessage.java | 204 +++++++++ .../models/v1/inbounds/TextMessageImpl.java | 304 ++++++++++++++ .../ListInboundMessagesQueryParameters.java | 144 +++++++ ...istInboundMessagesQueryParametersImpl.java | 163 +++++++ .../response/internal/ApiInboundList.java | 104 +++++ .../response/internal/ApiInboundListImpl.java | 176 ++++++++ .../response/internal/InboundInternal.java | 16 + .../internal/InboundInternalImpl.java | 397 ++++++++++++++++++ 19 files changed, 3331 insertions(+) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessageImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessage.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBody.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetails.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetailsImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessage.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessageImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParameters.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParametersImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternal.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternalImpl.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java new file mode 100644 index 000000000..6bd16ffe7 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java @@ -0,0 +1,246 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1.internal; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.databind.query_parameter.CollectionStringToCommaSerializer; +import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.HttpStatus; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameterUtils; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +public class InboundsApi { + + private static final Logger LOGGER = Logger.getLogger(InboundsApi.class.getName()); + private HttpClient httpClient; + private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; + private HttpMapper mapper; + + private final String servicePlanId; + + public InboundsApi( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper, + String servicePlanId) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + this.servicePlanId = servicePlanId; + } + + /** + * List incoming messages With the list operation, you can list all inbound messages that you have + * received. This operation supports pagination. Inbounds are returned in reverse chronological + * order. + * + * @param queryParameter (optional) + * @return ApiInboundList + * @throws ApiException if fails to make API call + */ + public ApiInboundList list(ListInboundMessagesQueryParameters queryParameter) + throws ApiException { + + LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); + + HttpRequest httpRequest = listRequestBuilder(queryParameter); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest listRequestBuilder(ListInboundMessagesQueryParameters queryParameter) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling list"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/inbounds" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPage(), "page", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getPageSize(), + "page_size", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getTo(), + "to", + URLParameter.form, + CollectionStringToCommaSerializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getStartDate(), + "start_date", + URLParameter.form, + InstantToIso8601Serializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getEndDate(), + "end_date", + URLParameter.form, + InstantToIso8601Serializer.getInstance(), + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getClientReference(), + "client_reference", + URLParameter.form, + null, + localVarQueryParams, + true); + } + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Retrieve inbound message This operation retrieves a specific inbound message with the provided + * inbound ID. + * + * @param inboundId The inbound ID found when listing inbound messages. (required) + * @return InboundMessage + * @throws ApiException if fails to make API call + */ + public InboundMessage get(String inboundId) throws ApiException { + + LOGGER.finest("[get]" + " " + "inboundId: " + inboundId); + + HttpRequest httpRequest = getRequestBuilder(inboundId); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest getRequestBuilder(String inboundId) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling get"); + } + // verify the required parameter 'inboundId' is set + if (inboundId == null) { + throw new ApiException(400, "Missing the required parameter 'inboundId' when calling get"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/inbounds/{inbound_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "inbound_id" + "\\}", URLPathUtils.encodePathSegment(inboundId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java index a5d2201cd..4d7790765 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/DryRunQueryParametersImpl.java @@ -68,6 +68,9 @@ static class Builder implements DryRunQueryParameters.Builder { protected Builder() {} protected Builder(DryRunQueryParameters _parameters) { + if (null == _parameters) { + return; + } DryRunQueryParametersImpl parameters = (DryRunQueryParametersImpl) _parameters; this.perRecipient = parameters.getPerRecipient(); this.numberOfRecipients = parameters.getNumberOfRecipients(); diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java index 8372d2cca..2d93afea2 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/ListBatchesQueryParametersImpl.java @@ -110,6 +110,9 @@ static class Builder implements ListBatchesQueryParameters.Builder { protected Builder() {} protected Builder(ListBatchesQueryParameters _parameters) { + if (null == _parameters) { + return; + } ListBatchesQueryParametersImpl parameters = (ListBatchesQueryParametersImpl) _parameters; this.page = parameters.getPage(); this.pageSize = parameters.getPageSize(); diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java new file mode 100644 index 000000000..b01a05724 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java @@ -0,0 +1,220 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.time.Instant; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Binary MO */ +@JsonDeserialize(builder = BinaryMessageImpl.Builder.class) +public interface BinaryMessage extends InboundMessage { + + /** + * If this inbound message is in response to a previously sent message that contained a client + * reference, then this field contains that client reference. Utilizing this feature + * requires additional setup on your account. Contact your account manager to enable this + * feature. + * + * @return clientReference + */ + String getClientReference(); + + /** + * The phone number that sent the message. More info + * + * @return from + */ + String getFrom(); + + /** + * The ID of this inbound message. + * + * @return id + */ + String getId(); + + /** + * The MCC/MNC of the sender's operator if known. + * + * @return operatorId + */ + String getOperatorId(); + + /** + * When the system received the message. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return receivedAt + */ + Instant getReceivedAt(); + + /** + * When the message left the originating device. Only available if provided by operator. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sentAt + */ + Instant getSentAt(); + + /** + * The Sinch phone number or short code to which the message was sent. + * + * @return to + */ + String getTo(); + + /** SMS in binary format */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MO_BINARY = new TypeEnum("mo_binary"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MO_BINARY)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * The message content Base64 encoded. Max 140 bytes together with udh. + * + * @return body + */ + String getBody(); + + /** + * The UDH header of a binary message HEX encoded. Max 140 bytes together with body. + * + * @return udh + */ + String getUdh(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BinaryMessageImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + */ + Builder setId(String id); + + /** + * see getter + * + * @param operatorId see getter + * @return Current builder + * @see #getOperatorId + */ + Builder setOperatorId(String operatorId); + + /** + * see getter + * + * @param receivedAt see getter + * @return Current builder + * @see #getReceivedAt + */ + Builder setReceivedAt(Instant receivedAt); + + /** + * see getter + * + * @param sentAt see getter + * @return Current builder + * @see #getSentAt + */ + Builder setSentAt(Instant sentAt); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(String to); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * see getter + * + * @param udh see getter + * @return Current builder + * @see #getUdh + */ + Builder setUdh(String udh); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BinaryMessage build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessageImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessageImpl.java new file mode 100644 index 000000000..f94b3ed6c --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessageImpl.java @@ -0,0 +1,332 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Objects; + +@JsonPropertyOrder({ + BinaryMessageImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BinaryMessageImpl.JSON_PROPERTY_FROM, + BinaryMessageImpl.JSON_PROPERTY_ID, + BinaryMessageImpl.JSON_PROPERTY_OPERATOR_ID, + BinaryMessageImpl.JSON_PROPERTY_RECEIVED_AT, + BinaryMessageImpl.JSON_PROPERTY_SENT_AT, + BinaryMessageImpl.JSON_PROPERTY_TO, + BinaryMessageImpl.JSON_PROPERTY_TYPE, + BinaryMessageImpl.JSON_PROPERTY_BODY, + BinaryMessageImpl.JSON_PROPERTY_UDH +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BinaryMessageImpl implements BinaryMessage, InboundMessage { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_OPERATOR_ID = "operator_id"; + + private OptionalValue operatorId; + + public static final String JSON_PROPERTY_RECEIVED_AT = "received_at"; + + private OptionalValue receivedAt; + + public static final String JSON_PROPERTY_SENT_AT = "sent_at"; + + private OptionalValue sentAt; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue to; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public static final String JSON_PROPERTY_UDH = "udh"; + + private OptionalValue udh; + + public BinaryMessageImpl() {} + + protected BinaryMessageImpl( + OptionalValue clientReference, + OptionalValue from, + OptionalValue id, + OptionalValue operatorId, + OptionalValue receivedAt, + OptionalValue sentAt, + OptionalValue to, + OptionalValue type, + OptionalValue body, + OptionalValue udh) { + this.clientReference = clientReference; + this.from = from; + this.id = id; + this.operatorId = operatorId; + this.receivedAt = receivedAt; + this.sentAt = sentAt; + this.to = to; + this.type = type; + this.body = body; + this.udh = udh; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue id() { + return id; + } + + @JsonIgnore + public String getOperatorId() { + return operatorId.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operatorId() { + return operatorId; + } + + @JsonIgnore + public Instant getReceivedAt() { + return receivedAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECEIVED_AT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue receivedAt() { + return receivedAt; + } + + @JsonIgnore + public Instant getSentAt() { + return sentAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SENT_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sentAt() { + return sentAt; + } + + @JsonIgnore + public String getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue to() { + return to; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue body() { + return body; + } + + @JsonIgnore + public String getUdh() { + return udh.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UDH) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue udh() { + return udh; + } + + /** Return true if this MOBinary object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BinaryMessageImpl moBinary = (BinaryMessageImpl) o; + return Objects.equals(this.clientReference, moBinary.clientReference) + && Objects.equals(this.from, moBinary.from) + && Objects.equals(this.id, moBinary.id) + && Objects.equals(this.operatorId, moBinary.operatorId) + && Objects.equals(this.receivedAt, moBinary.receivedAt) + && Objects.equals(this.sentAt, moBinary.sentAt) + && Objects.equals(this.to, moBinary.to) + && Objects.equals(this.type, moBinary.type) + && Objects.equals(this.body, moBinary.body) + && Objects.equals(this.udh, moBinary.udh); + } + + @Override + public int hashCode() { + return Objects.hash( + clientReference, from, id, operatorId, receivedAt, sentAt, to, type, body, udh); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BinaryMessageImpl {\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" operatorId: ").append(toIndentedString(operatorId)).append("\n"); + sb.append(" receivedAt: ").append(toIndentedString(receivedAt)).append("\n"); + sb.append(" sentAt: ").append(toIndentedString(sentAt)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).append("\n"); + sb.append(" udh: ").append(toIndentedString(udh)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BinaryMessage.Builder { + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue id = OptionalValue.empty(); + OptionalValue operatorId = OptionalValue.empty(); + OptionalValue receivedAt = OptionalValue.empty(); + OptionalValue sentAt = OptionalValue.empty(); + OptionalValue to = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MO_BINARY); + OptionalValue body = OptionalValue.empty(); + OptionalValue udh = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_ID) + public Builder setOperatorId(String operatorId) { + this.operatorId = OptionalValue.of(operatorId); + return this; + } + + @JsonProperty(JSON_PROPERTY_RECEIVED_AT) + public Builder setReceivedAt(Instant receivedAt) { + this.receivedAt = OptionalValue.of(receivedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_SENT_AT) + public Builder setSentAt(Instant sentAt) { + this.sentAt = OptionalValue.of(sentAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(String to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + @JsonProperty(JSON_PROPERTY_UDH) + public Builder setUdh(String udh) { + this.udh = OptionalValue.of(udh); + return this; + } + + public BinaryMessage build() { + return new BinaryMessageImpl( + clientReference, from, id, operatorId, receivedAt, sentAt, to, type, body, udh); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessage.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessage.java new file mode 100644 index 000000000..414f682ae --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessage.java @@ -0,0 +1,204 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.time.Instant; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Media MO */ +@JsonDeserialize(builder = MediaMessageImpl.Builder.class) +public interface MediaMessage extends InboundMessage { + + /** + * If this inbound message is in response to a previously sent message that contained a client + * reference, then this field contains that client reference. Utilizing this feature + * requires additional setup on your account. Contact your account manager to enable this + * feature. + * + * @return clientReference + */ + String getClientReference(); + + /** + * The phone number that sent the message. More info + * + * @return from + */ + String getFrom(); + + /** + * The ID of this inbound message. + * + * @return id + */ + String getId(); + + /** + * The MCC/MNC of the sender's operator if known. + * + * @return operatorId + */ + String getOperatorId(); + + /** + * When the system received the message. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return receivedAt + */ + Instant getReceivedAt(); + + /** + * When the message left the originating device. Only available if provided by operator. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sentAt + */ + Instant getSentAt(); + + /** + * The Sinch phone number or short code to which the message was sent. + * + * @return to + */ + String getTo(); + + /** MMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MO_MEDIA = new TypeEnum("mo_media"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MO_MEDIA)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Get body + * + * @return body + */ + MediaMessageBody getBody(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new MediaMessageImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + */ + Builder setId(String id); + + /** + * see getter + * + * @param operatorId see getter + * @return Current builder + * @see #getOperatorId + */ + Builder setOperatorId(String operatorId); + + /** + * see getter + * + * @param receivedAt see getter + * @return Current builder + * @see #getReceivedAt + */ + Builder setReceivedAt(Instant receivedAt); + + /** + * see getter + * + * @param sentAt see getter + * @return Current builder + * @see #getSentAt + */ + Builder setSentAt(Instant sentAt); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(String to); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(MediaMessageBody body); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + MediaMessage build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBody.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBody.java new file mode 100644 index 000000000..479c20abc --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBody.java @@ -0,0 +1,87 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; + +/** The message content, including a URL to the media filters. */ +@JsonDeserialize(builder = MediaMessageBodyImpl.Builder.class) +public interface MediaMessageBody { + + /** + * The subject of the MMS media message. + * + * @return subject + */ + String getSubject(); + + /** + * The text message content of the MMS media message. + * + * @return message + */ + String getMessage(); + + /** + * Get media + * + * @return media + */ + List getMedia(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new MediaMessageBodyImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param subject see getter + * @return Current builder + * @see #getSubject + */ + Builder setSubject(String subject); + + /** + * see getter + * + * @param message see getter + * @return Current builder + * @see #getMessage + */ + Builder setMessage(String message); + + /** + * see getter + * + * @param media see getter + * @return Current builder + * @see #getMedia + */ + Builder setMedia(List media); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + MediaMessageBody build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetails.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetails.java new file mode 100644 index 000000000..b24970676 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetails.java @@ -0,0 +1,102 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** MediaMessageBodyDetails */ +@JsonDeserialize(builder = MediaMessageBodyDetailsImpl.Builder.class) +public interface MediaMessageBodyDetails { + + /** + * URL to the media file + * + * @return url + */ + String getUrl(); + + /** + * The type of media file included in the message + * + * @return contentType + */ + String getContentType(); + + /** + * The status of the media upload + * + * @return status + */ + String getStatus(); + + /** + * Get code + * + * @return code + */ + Integer getCode(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new MediaMessageBodyDetailsImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param url see getter + * @return Current builder + * @see #getUrl + */ + Builder setUrl(String url); + + /** + * see getter + * + * @param contentType see getter + * @return Current builder + * @see #getContentType + */ + Builder setContentType(String contentType); + + /** + * see getter + * + * @param status see getter + * @return Current builder + * @see #getStatus + */ + Builder setStatus(String status); + + /** + * see getter + * + * @param code see getter + * @return Current builder + * @see #getCode + */ + Builder setCode(Integer code); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + MediaMessageBodyDetails build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetailsImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetailsImpl.java new file mode 100644 index 000000000..dc54be22b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyDetailsImpl.java @@ -0,0 +1,174 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +@JsonPropertyOrder({ + MediaMessageBodyDetailsImpl.JSON_PROPERTY_URL, + MediaMessageBodyDetailsImpl.JSON_PROPERTY_CONTENT_TYPE, + MediaMessageBodyDetailsImpl.JSON_PROPERTY_STATUS, + MediaMessageBodyDetailsImpl.JSON_PROPERTY_CODE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class MediaMessageBodyDetailsImpl implements MediaMessageBodyDetails { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_URL = "url"; + + private OptionalValue url; + + public static final String JSON_PROPERTY_CONTENT_TYPE = "contentType"; + + private OptionalValue contentType; + + public static final String JSON_PROPERTY_STATUS = "status"; + + private OptionalValue status; + + public static final String JSON_PROPERTY_CODE = "code"; + + private OptionalValue code; + + public MediaMessageBodyDetailsImpl() {} + + protected MediaMessageBodyDetailsImpl( + OptionalValue url, + OptionalValue contentType, + OptionalValue status, + OptionalValue code) { + this.url = url; + this.contentType = contentType; + this.status = status; + this.code = code; + } + + @JsonIgnore + public String getUrl() { + return url.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_URL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue url() { + return url; + } + + @JsonIgnore + public String getContentType() { + return contentType.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CONTENT_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue contentType() { + return contentType; + } + + @JsonIgnore + public String getStatus() { + return status.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STATUS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue status() { + return status; + } + + @JsonIgnore + public Integer getCode() { + return code.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue code() { + return code; + } + + /** Return true if this MOMediaBody_media_inner object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MediaMessageBodyDetailsImpl moMediaBodyMediaInner = (MediaMessageBodyDetailsImpl) o; + return Objects.equals(this.url, moMediaBodyMediaInner.url) + && Objects.equals(this.contentType, moMediaBodyMediaInner.contentType) + && Objects.equals(this.status, moMediaBodyMediaInner.status) + && Objects.equals(this.code, moMediaBodyMediaInner.code); + } + + @Override + public int hashCode() { + return Objects.hash(url, contentType, status, code); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MediaMessageBodyDetailsImpl {\n"); + sb.append(" url: ").append(toIndentedString(url)).append("\n"); + sb.append(" contentType: ").append(toIndentedString(contentType)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements MediaMessageBodyDetails.Builder { + OptionalValue url = OptionalValue.empty(); + OptionalValue contentType = OptionalValue.empty(); + OptionalValue status = OptionalValue.empty(); + OptionalValue code = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_URL) + public Builder setUrl(String url) { + this.url = OptionalValue.of(url); + return this; + } + + @JsonProperty(JSON_PROPERTY_CONTENT_TYPE) + public Builder setContentType(String contentType) { + this.contentType = OptionalValue.of(contentType); + return this; + } + + @JsonProperty(JSON_PROPERTY_STATUS) + public Builder setStatus(String status) { + this.status = OptionalValue.of(status); + return this; + } + + @JsonProperty(JSON_PROPERTY_CODE) + public Builder setCode(Integer code) { + this.code = OptionalValue.of(code); + return this; + } + + public MediaMessageBodyDetails build() { + return new MediaMessageBodyDetailsImpl(url, contentType, status, code); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyImpl.java new file mode 100644 index 000000000..6fd480549 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageBodyImpl.java @@ -0,0 +1,148 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + MediaMessageBodyImpl.JSON_PROPERTY_SUBJECT, + MediaMessageBodyImpl.JSON_PROPERTY_MESSAGE, + MediaMessageBodyImpl.JSON_PROPERTY_MEDIA +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class MediaMessageBodyImpl implements MediaMessageBody { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_SUBJECT = "subject"; + + private OptionalValue subject; + + public static final String JSON_PROPERTY_MESSAGE = "message"; + + private OptionalValue message; + + public static final String JSON_PROPERTY_MEDIA = "media"; + + private OptionalValue> media; + + public MediaMessageBodyImpl() {} + + protected MediaMessageBodyImpl( + OptionalValue subject, + OptionalValue message, + OptionalValue> media) { + this.subject = subject; + this.message = message; + this.media = media; + } + + @JsonIgnore + public String getSubject() { + return subject.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SUBJECT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue subject() { + return subject; + } + + @JsonIgnore + public String getMessage() { + return message.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue message() { + return message; + } + + @JsonIgnore + public List getMedia() { + return media.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MEDIA) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> media() { + return media; + } + + /** Return true if this MOMediaBody object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MediaMessageBodyImpl moMediaBody = (MediaMessageBodyImpl) o; + return Objects.equals(this.subject, moMediaBody.subject) + && Objects.equals(this.message, moMediaBody.message) + && Objects.equals(this.media, moMediaBody.media); + } + + @Override + public int hashCode() { + return Objects.hash(subject, message, media); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MediaMessageBodyImpl {\n"); + sb.append(" subject: ").append(toIndentedString(subject)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append(" media: ").append(toIndentedString(media)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements MediaMessageBody.Builder { + OptionalValue subject = OptionalValue.empty(); + OptionalValue message = OptionalValue.empty(); + OptionalValue> media = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_SUBJECT) + public Builder setSubject(String subject) { + this.subject = OptionalValue.of(subject); + return this; + } + + @JsonProperty(JSON_PROPERTY_MESSAGE) + public Builder setMessage(String message) { + this.message = OptionalValue.of(message); + return this; + } + + @JsonProperty(JSON_PROPERTY_MEDIA) + public Builder setMedia(List media) { + this.media = OptionalValue.of(media); + return this; + } + + public MediaMessageBody build() { + return new MediaMessageBodyImpl(subject, message, media); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageImpl.java new file mode 100644 index 000000000..dd536688b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/MediaMessageImpl.java @@ -0,0 +1,304 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Objects; + +@JsonPropertyOrder({ + MediaMessageImpl.JSON_PROPERTY_CLIENT_REFERENCE, + MediaMessageImpl.JSON_PROPERTY_FROM, + MediaMessageImpl.JSON_PROPERTY_ID, + MediaMessageImpl.JSON_PROPERTY_OPERATOR_ID, + MediaMessageImpl.JSON_PROPERTY_RECEIVED_AT, + MediaMessageImpl.JSON_PROPERTY_SENT_AT, + MediaMessageImpl.JSON_PROPERTY_TO, + MediaMessageImpl.JSON_PROPERTY_TYPE, + MediaMessageImpl.JSON_PROPERTY_BODY +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class MediaMessageImpl implements MediaMessage, InboundMessage { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_OPERATOR_ID = "operator_id"; + + private OptionalValue operatorId; + + public static final String JSON_PROPERTY_RECEIVED_AT = "received_at"; + + private OptionalValue receivedAt; + + public static final String JSON_PROPERTY_SENT_AT = "sent_at"; + + private OptionalValue sentAt; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue to; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public MediaMessageImpl() {} + + protected MediaMessageImpl( + OptionalValue clientReference, + OptionalValue from, + OptionalValue id, + OptionalValue operatorId, + OptionalValue receivedAt, + OptionalValue sentAt, + OptionalValue to, + OptionalValue type, + OptionalValue body) { + this.clientReference = clientReference; + this.from = from; + this.id = id; + this.operatorId = operatorId; + this.receivedAt = receivedAt; + this.sentAt = sentAt; + this.to = to; + this.type = type; + this.body = body; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue id() { + return id; + } + + @JsonIgnore + public String getOperatorId() { + return operatorId.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operatorId() { + return operatorId; + } + + @JsonIgnore + public Instant getReceivedAt() { + return receivedAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECEIVED_AT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue receivedAt() { + return receivedAt; + } + + @JsonIgnore + public Instant getSentAt() { + return sentAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SENT_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sentAt() { + return sentAt; + } + + @JsonIgnore + public String getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue to() { + return to; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + @JsonIgnore + public MediaMessageBody getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue body() { + return body; + } + + /** Return true if this MOMedia object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MediaMessageImpl moMedia = (MediaMessageImpl) o; + return Objects.equals(this.clientReference, moMedia.clientReference) + && Objects.equals(this.from, moMedia.from) + && Objects.equals(this.id, moMedia.id) + && Objects.equals(this.operatorId, moMedia.operatorId) + && Objects.equals(this.receivedAt, moMedia.receivedAt) + && Objects.equals(this.sentAt, moMedia.sentAt) + && Objects.equals(this.to, moMedia.to) + && Objects.equals(this.type, moMedia.type) + && Objects.equals(this.body, moMedia.body); + } + + @Override + public int hashCode() { + return Objects.hash(clientReference, from, id, operatorId, receivedAt, sentAt, to, type, body); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MediaMessageImpl {\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" operatorId: ").append(toIndentedString(operatorId)).append("\n"); + sb.append(" receivedAt: ").append(toIndentedString(receivedAt)).append("\n"); + sb.append(" sentAt: ").append(toIndentedString(sentAt)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements MediaMessage.Builder { + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue id = OptionalValue.empty(); + OptionalValue operatorId = OptionalValue.empty(); + OptionalValue receivedAt = OptionalValue.empty(); + OptionalValue sentAt = OptionalValue.empty(); + OptionalValue to = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MO_MEDIA); + OptionalValue body = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_ID) + public Builder setOperatorId(String operatorId) { + this.operatorId = OptionalValue.of(operatorId); + return this; + } + + @JsonProperty(JSON_PROPERTY_RECEIVED_AT) + public Builder setReceivedAt(Instant receivedAt) { + this.receivedAt = OptionalValue.of(receivedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_SENT_AT) + public Builder setSentAt(Instant sentAt) { + this.sentAt = OptionalValue.of(sentAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(String to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(MediaMessageBody body) { + this.body = OptionalValue.of(body); + return this; + } + + public MediaMessage build() { + return new MediaMessageImpl( + clientReference, from, id, operatorId, receivedAt, sentAt, to, type, body); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessage.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessage.java new file mode 100644 index 000000000..7511ae725 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessage.java @@ -0,0 +1,204 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.time.Instant; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Text MO */ +@JsonDeserialize(builder = TextMessageImpl.Builder.class) +public interface TextMessage extends InboundMessage { + + /** + * If this inbound message is in response to a previously sent message that contained a client + * reference, then this field contains that client reference. Utilizing this feature + * requires additional setup on your account. Contact your account manager to enable this + * feature. + * + * @return clientReference + */ + String getClientReference(); + + /** + * The phone number that sent the message. More info + * + * @return from + */ + String getFrom(); + + /** + * The ID of this inbound message. + * + * @return id + */ + String getId(); + + /** + * The MCC/MNC of the sender's operator if known. + * + * @return operatorId + */ + String getOperatorId(); + + /** + * When the system received the message. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return receivedAt + */ + Instant getReceivedAt(); + + /** + * When the message left the originating device. Only available if provided by operator. Formatted + * as ISO-8601: + * YYYY-MM-DDThh:mm:ss.SSSZ. + * + * @return sentAt + */ + Instant getSentAt(); + + /** + * The Sinch phone number or short code to which the message was sent. + * + * @return to + */ + String getTo(); + + /** Regular SMS */ + public class TypeEnum extends EnumDynamic { + public static final TypeEnum MO_TEXT = new TypeEnum("mo_text"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(MO_TEXT)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + /** + * Get body + * + * @return body + */ + String getBody(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new TextMessageImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param from see getter + * @return Current builder + * @see #getFrom + */ + Builder setFrom(String from); + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + */ + Builder setId(String id); + + /** + * see getter + * + * @param operatorId see getter + * @return Current builder + * @see #getOperatorId + */ + Builder setOperatorId(String operatorId); + + /** + * see getter + * + * @param receivedAt see getter + * @return Current builder + * @see #getReceivedAt + */ + Builder setReceivedAt(Instant receivedAt); + + /** + * see getter + * + * @param sentAt see getter + * @return Current builder + * @see #getSentAt + */ + Builder setSentAt(Instant sentAt); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(String to); + + /** + * see getter + * + * @param body see getter + * @return Current builder + * @see #getBody + */ + Builder setBody(String body); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TextMessage build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessageImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessageImpl.java new file mode 100644 index 000000000..79f0612b2 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/TextMessageImpl.java @@ -0,0 +1,304 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Objects; + +@JsonPropertyOrder({ + TextMessageImpl.JSON_PROPERTY_CLIENT_REFERENCE, + TextMessageImpl.JSON_PROPERTY_FROM, + TextMessageImpl.JSON_PROPERTY_ID, + TextMessageImpl.JSON_PROPERTY_OPERATOR_ID, + TextMessageImpl.JSON_PROPERTY_RECEIVED_AT, + TextMessageImpl.JSON_PROPERTY_SENT_AT, + TextMessageImpl.JSON_PROPERTY_TO, + TextMessageImpl.JSON_PROPERTY_TYPE, + TextMessageImpl.JSON_PROPERTY_BODY +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TextMessageImpl implements TextMessage, InboundMessage { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_FROM = "from"; + + private OptionalValue from; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_OPERATOR_ID = "operator_id"; + + private OptionalValue operatorId; + + public static final String JSON_PROPERTY_RECEIVED_AT = "received_at"; + + private OptionalValue receivedAt; + + public static final String JSON_PROPERTY_SENT_AT = "sent_at"; + + private OptionalValue sentAt; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue to; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public static final String JSON_PROPERTY_BODY = "body"; + + private OptionalValue body; + + public TextMessageImpl() {} + + protected TextMessageImpl( + OptionalValue clientReference, + OptionalValue from, + OptionalValue id, + OptionalValue operatorId, + OptionalValue receivedAt, + OptionalValue sentAt, + OptionalValue to, + OptionalValue type, + OptionalValue body) { + this.clientReference = clientReference; + this.from = from; + this.id = id; + this.operatorId = operatorId; + this.receivedAt = receivedAt; + this.sentAt = sentAt; + this.to = to; + this.type = type; + this.body = body; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public String getFrom() { + return from.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FROM) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue from() { + return from; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue id() { + return id; + } + + @JsonIgnore + public String getOperatorId() { + return operatorId.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operatorId() { + return operatorId; + } + + @JsonIgnore + public Instant getReceivedAt() { + return receivedAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECEIVED_AT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue receivedAt() { + return receivedAt; + } + + @JsonIgnore + public Instant getSentAt() { + return sentAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SENT_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue sentAt() { + return sentAt; + } + + @JsonIgnore + public String getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue to() { + return to; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + @JsonIgnore + public String getBody() { + return body.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_BODY) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue body() { + return body; + } + + /** Return true if this MOText object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TextMessageImpl moText = (TextMessageImpl) o; + return Objects.equals(this.clientReference, moText.clientReference) + && Objects.equals(this.from, moText.from) + && Objects.equals(this.id, moText.id) + && Objects.equals(this.operatorId, moText.operatorId) + && Objects.equals(this.receivedAt, moText.receivedAt) + && Objects.equals(this.sentAt, moText.sentAt) + && Objects.equals(this.to, moText.to) + && Objects.equals(this.type, moText.type) + && Objects.equals(this.body, moText.body); + } + + @Override + public int hashCode() { + return Objects.hash(clientReference, from, id, operatorId, receivedAt, sentAt, to, type, body); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TextMessageImpl {\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" from: ").append(toIndentedString(from)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" operatorId: ").append(toIndentedString(operatorId)).append("\n"); + sb.append(" receivedAt: ").append(toIndentedString(receivedAt)).append("\n"); + sb.append(" sentAt: ").append(toIndentedString(sentAt)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" body: ").append(toIndentedString(body)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements TextMessage.Builder { + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue from = OptionalValue.empty(); + OptionalValue id = OptionalValue.empty(); + OptionalValue operatorId = OptionalValue.empty(); + OptionalValue receivedAt = OptionalValue.empty(); + OptionalValue sentAt = OptionalValue.empty(); + OptionalValue to = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.MO_TEXT); + OptionalValue body = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_FROM) + public Builder setFrom(String from) { + this.from = OptionalValue.of(from); + return this; + } + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_ID) + public Builder setOperatorId(String operatorId) { + this.operatorId = OptionalValue.of(operatorId); + return this; + } + + @JsonProperty(JSON_PROPERTY_RECEIVED_AT) + public Builder setReceivedAt(Instant receivedAt) { + this.receivedAt = OptionalValue.of(receivedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_SENT_AT) + public Builder setSentAt(Instant sentAt) { + this.sentAt = OptionalValue.of(sentAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(String to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_BODY) + public Builder setBody(String body) { + this.body = OptionalValue.of(body); + return this; + } + + public TextMessage build() { + return new TextMessageImpl( + clientReference, from, id, operatorId, receivedAt, sentAt, to, type, body); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParameters.java new file mode 100644 index 000000000..dd6021cf4 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParameters.java @@ -0,0 +1,144 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Collection; + +/** ListInboundMessagesQueryParameters */ +public interface ListInboundMessagesQueryParameters { + + /** + * Get page minimum: 0 + * + * @return page + */ + OptionalValue getPage(); + + /** + * Get pageSize maximum: 100 + * + * @return pageSize + */ + OptionalValue getPageSize(); + + /** + * Get to + * + * @return to + */ + OptionalValue> getTo(); + + /** + * Get startDate + * + * @return startDate + */ + OptionalValue getStartDate(); + + /** + * Get endDate + * + * @return endDate + */ + OptionalValue getEndDate(); + + /** + * Get clientReference + * + * @return clientReference + */ + OptionalValue getClientReference(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ListInboundMessagesQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(ListInboundMessagesQueryParameters parameters) { + return new ListInboundMessagesQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(Collection to); + + /** + * see getter + * + * @param startDate see getter + * @return Current builder + * @see #getStartDate + */ + Builder setStartDate(Instant startDate); + + /** + * see getter + * + * @param endDate see getter + * @return Current builder + * @see #getEndDate + */ + Builder setEndDate(Instant endDate); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ListInboundMessagesQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParametersImpl.java new file mode 100644 index 000000000..8c1fb3d40 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/ListInboundMessagesQueryParametersImpl.java @@ -0,0 +1,163 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Collection; +import java.util.Objects; + +public class ListInboundMessagesQueryParametersImpl implements ListInboundMessagesQueryParameters { + + private final OptionalValue page; + private final OptionalValue pageSize; + private final OptionalValue> to; + private final OptionalValue startDate; + private final OptionalValue endDate; + private final OptionalValue clientReference; + + private ListInboundMessagesQueryParametersImpl( + OptionalValue page, + OptionalValue pageSize, + OptionalValue> to, + OptionalValue startDate, + OptionalValue endDate, + OptionalValue clientReference) { + this.page = page; + this.pageSize = pageSize; + this.to = to; + this.startDate = startDate; + this.endDate = endDate; + this.clientReference = clientReference; + } + + public OptionalValue getPage() { + return page; + } + + public OptionalValue getPageSize() { + return pageSize; + } + + public OptionalValue> getTo() { + return to; + } + + public OptionalValue getStartDate() { + return startDate; + } + + public OptionalValue getEndDate() { + return endDate; + } + + public OptionalValue getClientReference() { + return clientReference; + } + + /** Return true if this ListInboundMessagesQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ListInboundMessagesQueryParametersImpl listInboundMessagesQueryParameters = + (ListInboundMessagesQueryParametersImpl) o; + return Objects.equals(this.page, listInboundMessagesQueryParameters.page) + && Objects.equals(this.pageSize, listInboundMessagesQueryParameters.pageSize) + && Objects.equals(this.to, listInboundMessagesQueryParameters.to) + && Objects.equals(this.startDate, listInboundMessagesQueryParameters.startDate) + && Objects.equals(this.endDate, listInboundMessagesQueryParameters.endDate) + && Objects.equals(this.clientReference, listInboundMessagesQueryParameters.clientReference); + } + + @Override + public int hashCode() { + return Objects.hash(page, pageSize, to, startDate, endDate, clientReference); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ListInboundMessagesQueryParametersImpl {\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" startDate: ").append(toIndentedString(startDate)).append("\n"); + sb.append(" endDate: ").append(toIndentedString(endDate)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).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 "); + } + + static class Builder implements ListInboundMessagesQueryParameters.Builder { + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + OptionalValue> to = OptionalValue.empty(); + OptionalValue startDate = OptionalValue.empty(); + OptionalValue endDate = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(ListInboundMessagesQueryParameters _parameters) { + if (null == _parameters) { + return; + } + ListInboundMessagesQueryParametersImpl parameters = + (ListInboundMessagesQueryParametersImpl) _parameters; + this.page = parameters.getPage(); + this.pageSize = parameters.getPageSize(); + this.to = parameters.getTo(); + this.startDate = parameters.getStartDate(); + this.endDate = parameters.getEndDate(); + this.clientReference = parameters.getClientReference(); + } + + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public Builder setTo(Collection to) { + this.to = OptionalValue.of(to); + return this; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = OptionalValue.of(startDate); + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = OptionalValue.of(endDate); + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + public ListInboundMessagesQueryParameters build() { + return new ListInboundMessagesQueryParametersImpl( + page, pageSize, to, startDate, endDate, clientReference); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java new file mode 100644 index 000000000..0f8d61df9 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java @@ -0,0 +1,104 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import java.util.List; + +/** ApiInboundList */ +@JsonDeserialize(builder = ApiInboundListImpl.Builder.class) +public interface ApiInboundList { + + /** + * The total number of inbounds matching the given filters + * + * @return count + */ + Long getCount(); + + /** + * The requested page. + * + * @return page + */ + Integer getPage(); + + /** + * The page of inbounds matching the given filters. + * + * @return inbounds + */ + List getInbounds(); + + /** + * The number of inbounds returned in this request. + * + * @return pageSize + */ + Integer getPageSize(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ApiInboundListImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param count see getter + * @return Current builder + * @see #getCount + */ + Builder setCount(Long count); + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param inbounds see getter + * @return Current builder + * @see #getInbounds + */ + Builder setInbounds(List inbounds); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ApiInboundList build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java new file mode 100644 index 000000000..f1068f116 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java @@ -0,0 +1,176 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + ApiInboundListImpl.JSON_PROPERTY_COUNT, + ApiInboundListImpl.JSON_PROPERTY_PAGE, + ApiInboundListImpl.JSON_PROPERTY_INBOUNDS, + ApiInboundListImpl.JSON_PROPERTY_PAGE_SIZE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class ApiInboundListImpl implements ApiInboundList { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_COUNT = "count"; + + private OptionalValue count; + + public static final String JSON_PROPERTY_PAGE = "page"; + + private OptionalValue page; + + public static final String JSON_PROPERTY_INBOUNDS = "inbounds"; + + private OptionalValue> inbounds; + + public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; + + private OptionalValue pageSize; + + public ApiInboundListImpl() {} + + protected ApiInboundListImpl( + OptionalValue count, + OptionalValue page, + OptionalValue> inbounds, + OptionalValue pageSize) { + this.count = count; + this.page = page; + this.inbounds = inbounds; + this.pageSize = pageSize; + } + + @JsonIgnore + public Long getCount() { + return count.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue count() { + return count; + } + + @JsonIgnore + public Integer getPage() { + return page.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue page() { + return page; + } + + @JsonIgnore + public List getInbounds() { + return inbounds.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_INBOUNDS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> inbounds() { + return inbounds; + } + + @JsonIgnore + public Integer getPageSize() { + return pageSize.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue pageSize() { + return pageSize; + } + + /** Return true if this ApiInboundList object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ApiInboundListImpl apiInboundList = (ApiInboundListImpl) o; + return Objects.equals(this.count, apiInboundList.count) + && Objects.equals(this.page, apiInboundList.page) + && Objects.equals(this.inbounds, apiInboundList.inbounds) + && Objects.equals(this.pageSize, apiInboundList.pageSize); + } + + @Override + public int hashCode() { + return Objects.hash(count, page, inbounds, pageSize); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiInboundListImpl {\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" inbounds: ").append(toIndentedString(inbounds)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements ApiInboundList.Builder { + OptionalValue count = OptionalValue.empty(); + OptionalValue page = OptionalValue.empty(); + OptionalValue> inbounds = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_COUNT) + public Builder setCount(Long count) { + this.count = OptionalValue.of(count); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE) + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + @JsonProperty(JSON_PROPERTY_INBOUNDS) + public Builder setInbounds(List inbounds) { + this.inbounds = OptionalValue.of(inbounds); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public ApiInboundList build() { + return new ApiInboundListImpl(count, page, inbounds, pageSize); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternal.java new file mode 100644 index 000000000..b4bd24d00 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternal.java @@ -0,0 +1,16 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = InboundInternalImpl.InboundInternalImplDeserializer.class) +public interface InboundInternal {} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternalImpl.java new file mode 100644 index 000000000..e1cedddc1 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/InboundInternalImpl.java @@ -0,0 +1,397 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.utils.databind.JSONNavigator; +import com.sinch.sdk.domains.sms.models.v1.inbounds.BinaryMessageImpl; +import com.sinch.sdk.domains.sms.models.v1.inbounds.MediaMessageImpl; +import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessageImpl; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +@JsonDeserialize(using = InboundInternalImpl.InboundInternalImplDeserializer.class) +@JsonSerialize(using = InboundInternalImpl.InboundInternalImplSerializer.class) +public class InboundInternalImpl extends AbstractOpenApiSchema implements InboundInternal { + private static final Logger log = Logger.getLogger(InboundInternalImpl.class.getName()); + + public static final class InboundInternalImplSerializer + extends StdSerializer { + private static final long serialVersionUID = 1L; + + public InboundInternalImplSerializer(Class t) { + super(t); + } + + public InboundInternalImplSerializer() { + this(null); + } + + @Override + public void serialize( + InboundInternalImpl value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.getActualInstance()); + } + } + + public static final class InboundInternalImplDeserializer + extends StdDeserializer { + + private static final long serialVersionUID = 1L; + + public InboundInternalImplDeserializer() { + this(InboundInternalImpl.class); + } + + public InboundInternalImplDeserializer(Class vc) { + super(vc); + } + + @Override + public InboundInternalImpl deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode tree = jp.readValueAsTree(); + Object deserialized = null; + InboundInternalImpl newInboundInternalImpl = new InboundInternalImpl(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "mo_binary": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryMessageImpl.class); + newInboundInternalImpl.setActualInstance(deserialized); + return newInboundInternalImpl; + case "mo_media": + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaMessageImpl.class); + newInboundInternalImpl.setActualInstance(deserialized); + return newInboundInternalImpl; + case "mo_text": + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextMessageImpl.class); + newInboundInternalImpl.setActualInstance(deserialized); + return newInboundInternalImpl; + case "MOBinary": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryMessageImpl.class); + newInboundInternalImpl.setActualInstance(deserialized); + return newInboundInternalImpl; + case "MOMedia": + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaMessageImpl.class); + newInboundInternalImpl.setActualInstance(deserialized); + return newInboundInternalImpl; + case "MOText": + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextMessageImpl.class); + newInboundInternalImpl.setActualInstance(deserialized); + return newInboundInternalImpl; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for InboundInternalImpl. Possible" + + " values: mo_binary mo_media mo_text MOBinary MOMedia MOText", + discriminatorValue)); + } + + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize BinaryMessageImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BinaryMessageImpl.class.equals(Integer.class) + || BinaryMessageImpl.class.equals(Long.class) + || BinaryMessageImpl.class.equals(Float.class) + || BinaryMessageImpl.class.equals(Double.class) + || BinaryMessageImpl.class.equals(Boolean.class) + || BinaryMessageImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BinaryMessageImpl.class.equals(Integer.class) + || BinaryMessageImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BinaryMessageImpl.class.equals(Float.class) + || BinaryMessageImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BinaryMessageImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BinaryMessageImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryMessageImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BinaryMessageImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BinaryMessageImpl'", e); + } + + // deserialize MediaMessageImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (MediaMessageImpl.class.equals(Integer.class) + || MediaMessageImpl.class.equals(Long.class) + || MediaMessageImpl.class.equals(Float.class) + || MediaMessageImpl.class.equals(Double.class) + || MediaMessageImpl.class.equals(Boolean.class) + || MediaMessageImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((MediaMessageImpl.class.equals(Integer.class) + || MediaMessageImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((MediaMessageImpl.class.equals(Float.class) + || MediaMessageImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (MediaMessageImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (MediaMessageImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaMessageImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'MediaMessageImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'MediaMessageImpl'", e); + } + + // deserialize TextMessageImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (TextMessageImpl.class.equals(Integer.class) + || TextMessageImpl.class.equals(Long.class) + || TextMessageImpl.class.equals(Float.class) + || TextMessageImpl.class.equals(Double.class) + || TextMessageImpl.class.equals(Boolean.class) + || TextMessageImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((TextMessageImpl.class.equals(Integer.class) + || TextMessageImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((TextMessageImpl.class.equals(Float.class) + || TextMessageImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (TextMessageImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (TextMessageImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextMessageImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'TextMessageImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'TextMessageImpl'", e); + } + + if (match == 1) { + InboundInternalImpl ret = new InboundInternalImpl(); + ret.setActualInstance(deserialized); + return ret; + } + throw new IOException( + String.format( + "Failed deserialization for InboundInternalImpl: %d classes match result, expected 1", + match)); + } + + /** Handle deserialization of the 'null' value. */ + @Override + public InboundInternalImpl getNullValue(DeserializationContext ctxt) + throws JsonMappingException { + throw new JsonMappingException(ctxt.getParser(), "InboundInternalImpl cannot be null"); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap<>(); + + public InboundInternalImpl() { + super("oneOf", Boolean.FALSE); + } + + public InboundInternalImpl(BinaryMessageImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public InboundInternalImpl(MediaMessageImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public InboundInternalImpl(TextMessageImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("BinaryMessageImpl", BinaryMessageImpl.class); + schemas.put("MediaMessageImpl", MediaMessageImpl.class); + schemas.put("TextMessageImpl", TextMessageImpl.class); + JSONNavigator.registerDescendants( + InboundInternalImpl.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("mo_binary", BinaryMessageImpl.class); + mappings.put("mo_media", MediaMessageImpl.class); + mappings.put("mo_text", TextMessageImpl.class); + mappings.put("MOBinary", BinaryMessageImpl.class); + mappings.put("MOMedia", MediaMessageImpl.class); + mappings.put("MOText", TextMessageImpl.class); + mappings.put("inbound", InboundInternalImpl.class); + JSONNavigator.registerDiscriminator(InboundInternalImpl.class, "type", mappings); + } + + @Override + public Map> getSchemas() { + return InboundInternalImpl.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check the instance parameter is valid + * against the oneOf child schemas: BinaryMessageImpl, MediaMessageImpl, TextMessageImpl + * + *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a + * composed schema (allOf, anyOf, oneOf). + */ + @Override + public void setActualInstance(Object instance) { + if (JSONNavigator.isInstanceOf(BinaryMessageImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(MediaMessageImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(TextMessageImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException( + "Invalid instance type. Must be BinaryMessageImpl, MediaMessageImpl, TextMessageImpl"); + } + + /** + * Get the actual instance, which can be the following: BinaryMessageImpl, MediaMessageImpl, + * TextMessageImpl + * + * @return The actual instance (BinaryMessageImpl, MediaMessageImpl, TextMessageImpl) + */ + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `BinaryMessageImpl`. If the actual instance is not + * `BinaryMessageImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `BinaryMessageImpl` + * @throws ClassCastException if the instance is not `BinaryMessageImpl` + */ + public BinaryMessageImpl getBinaryMessageImpl() throws ClassCastException { + return (BinaryMessageImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `MediaMessageImpl`. If the actual instance is not + * `MediaMessageImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `MediaMessageImpl` + * @throws ClassCastException if the instance is not `MediaMessageImpl` + */ + public MediaMessageImpl getMediaMessageImpl() throws ClassCastException { + return (MediaMessageImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `TextMessageImpl`. If the actual instance is not `TextMessageImpl`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `TextMessageImpl` + * @throws ClassCastException if the instance is not `TextMessageImpl` + */ + public TextMessageImpl getTextMessageImpl() throws ClassCastException { + return (TextMessageImpl) super.getActualInstance(); + } + + public static class Deserializer + extends StdDeserializer { + + public Deserializer() { + this(null); + } + + public Deserializer(Class vc) { + super(vc); + } + + @Override + public com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage deserialize( + JsonParser jp, DeserializationContext ctxt) throws IOException { + + Object deserialized = jp.readValueAs(InboundInternalImpl.class).getActualInstance(); + if (null == deserialized) { + return null; + } + if (!(deserialized instanceof com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage)) { + log.log(Level.SEVERE, "Input data does not match schema ", deserialized); + return null; + } + + return (com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage) deserialized; + } + } +} From 5df68e3ef87c2755d744054861c6f728c830e0f2 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 19 Dec 2024 11:57:02 +0100 Subject: [PATCH 32/65] test: (SMS/Inbounds) Refactor V0 tests --- .../sdk/domains/sms/adapters/InboundsServiceTest.java | 10 +++++----- .../sdk/domains/sms/adapters/WebHooksServiceTest.java | 4 ++-- .../sdk/domains/sms/models/dto/v1/InboundDtoTest.java | 4 ++-- .../sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java | 4 ++-- .../sdk/domains/sms/models/dto/v1/MOTextDtoTest.java | 4 ++-- .../domains/sms/v1/{ => inbounds}/MOBinaryDto.json | 0 .../domains/sms/v1/{ => inbounds}/MOTextDto.json | 0 .../internal}/InboundsListResponseDtoPage0.json | 0 .../internal}/InboundsListResponseDtoPage1.json | 0 .../internal}/InboundsListResponseDtoPage2.json | 0 10 files changed, 13 insertions(+), 13 deletions(-) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => inbounds}/MOBinaryDto.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => inbounds}/MOTextDto.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => inbounds/response/internal}/InboundsListResponseDtoPage0.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => inbounds/response/internal}/InboundsListResponseDtoPage1.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => inbounds/response/internal}/InboundsListResponseDtoPage2.json (100%) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java index f75637c62..9d094bfe7 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java @@ -40,19 +40,19 @@ class InboundsServiceTest extends BaseTest { String uriPartID = "foovalue"; - @GivenJsonResource("/domains/sms/v1/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") InboundDto binary; - @GivenJsonResource("/domains/sms/v1/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") InboundDto text; - @GivenJsonResource("/domains/sms/v1/InboundsListResponseDtoPage0.json") + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") ApiInboundListDto inboundsLisResponseDtoPage0; - @GivenJsonResource("/domains/sms/v1/InboundsListResponseDtoPage1.json") + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json") ApiInboundListDto inboundsLisResponseDtoPage1; - @GivenJsonResource("/domains/sms/v1/InboundsListResponseDtoPage2.json") + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json") ApiInboundListDto inboundsLisResponseDtoPage2; @BeforeEach diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java index afe604226..1e863089e 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java @@ -28,10 +28,10 @@ @TestWithResources public class WebHooksServiceTest extends BaseTest { - @GivenTextResource("/domains/sms/v1/MOBinaryDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/MOBinaryDto.json") String incomingSMSBinaryJsonString; - @GivenTextResource("/domains/sms/v1/MOTextDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/MOTextDto.json") String incomingSMSTextJsonString; @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java index 8e36a4b93..83b73b8d9 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java @@ -10,10 +10,10 @@ @TestWithResources class InboundDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") InboundDto loadedBinaryMessage; - @GivenJsonResource("/domains/sms/v1/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") InboundDto loadedTextMessage; MOBinaryDto binaryDTO = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java index 97791df9f..6cea5b357 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources public class MOBinaryDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") MOBinaryDto loadedDto; - @GivenTextResource("/domains/sms/v1/MOBinaryDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/MOBinaryDto.json") String jsonStringDto; public static MOBinaryDto dto = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java index 066aa97a2..917f554c5 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources public class MOTextDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") MOTextDto loadedDto; - @GivenTextResource("/domains/sms/v1/MOTextDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/MOTextDto.json") String jsonStringDto; public static MOTextDto dto = diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/MOBinaryDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOBinaryDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/MOBinaryDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOBinaryDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/MOTextDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOTextDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/MOTextDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOTextDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage0.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage0.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage1.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage1.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage2.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/InboundsListResponseDtoPage2.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json From 1cdd88db54cc7425ae5b2b6df3bd40a454f575e0 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 19 Dec 2024 12:00:41 +0100 Subject: [PATCH 33/65] feat (SMS/Inbounds): inbounds API --- .../domains/sms/api/v1/InboundsService.java | 13 ++ .../sdk/domains/sms/api/v1/SMSService.java | 2 + .../sms/api/v1/adapters/BatchesService.java | 6 +- .../sms/api/v1/adapters/InboundsService.java | 50 ++++++ .../sms/api/v1/adapters/SMSService.java | 12 +- .../models/v1/inbounds/InboundMessage.java | 7 + .../response/ListInboundsResponse.java | 54 ++++++ .../api/v1/adapters/InboundsServiceTest.java | 162 ++++++++++++++++++ .../sms/api/v1/internal/InboundsApiTest.java | 141 +++++++++++++++ .../sdk/e2e/domains/sms/v1/InboundsSteps.java | 113 ++++++++++++ .../sinch/sdk/e2e/domains/sms/v1/SmsIT.java | 1 + .../CollectionStringToCommaSerializer.java | 27 +++ .../InstantToIso8601Serializer.java | 1 - ...CollectionStringToCommaSerializerTest.java | 49 ++++++ .../v1/inbounds/InboundMessageDtoTest.java | 89 ++++++++++ .../domains/sms/v1/inbounds/MOMediaDto.json | 22 +++ .../com/sinch/sample/sms/v1/inbounds/Get.java | 35 ++++ .../sinch/sample/sms/v1/inbounds/List.java | 41 +++++ 18 files changed, 818 insertions(+), 7 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/InboundsSteps.java create mode 100644 core/src/main/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializer.java create mode 100644 core/src/test/java/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializerTest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOMediaDto.json create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/Get.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/List.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java new file mode 100644 index 000000000..4861622b2 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java @@ -0,0 +1,13 @@ +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; + +public interface InboundsService { + + ListInboundsResponse list(ListInboundMessagesQueryParameters parameters) throws ApiException; + + InboundMessage get(String inboundId) throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java index b9bfd936a..1df50d22b 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -3,4 +3,6 @@ public interface SMSService { BatchesService batches(); + + InboundsService inbounds(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index e189c9484..cad456982 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -42,16 +42,12 @@ public BatchResponse send(BatchRequest batch) throws ApiException { public ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException { - ListBatchesQueryParameters guardParameters = - null != parameters ? parameters : ListBatchesQueryParameters.builder().build(); - ApiBatchList response = getApi().list(parameters); SMSCursorPageNavigator navigator = new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); - return new ListBatchesResponse( - this, new Page<>(guardParameters, response.getBatches(), navigator)); + return new ListBatchesResponse(this, new Page<>(parameters, response.getBatches(), navigator)); } public DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch) { diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java new file mode 100644 index 000000000..831fa3592 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java @@ -0,0 +1,50 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; +import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; +import com.sinch.sdk.models.SmsContext; +import java.util.Map; + +public class InboundsService implements com.sinch.sdk.domains.sms.api.v1.InboundsService { + + private final InboundsApi api; + + public InboundsService( + String uriUUID, + SmsContext context, + HttpClient httpClient, + Map authManagers) { + this.api = + new InboundsApi( + httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); + } + + protected InboundsApi getApi() { + return this.api; + } + + public ListInboundsResponse list(ListInboundMessagesQueryParameters parameters) + throws ApiException { + + ApiInboundList response = getApi().list(parameters); + + SMSCursorPageNavigator navigator = + new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); + + return new ListInboundsResponse( + this, new Page<>(parameters, response.getInbounds(), navigator)); + } + + public InboundMessage get(String inboundId) throws ApiException { + return getApi().get(inboundId); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index 84bde85fa..8820f3056 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -25,9 +25,11 @@ public class SMSService implements com.sinch.sdk.domains.sms.api.v1.SMSService { private final String uriUUID; private final SmsContext context; private final HttpClient httpClient; - private BatchesService batches; private final Map authManagers; + private BatchesService batches; + private InboundsService inbounds; + public SMSService( UnifiedCredentials credentials, SmsContext context, @@ -85,4 +87,12 @@ public BatchesService batches() { } return this.batches; } + + @Override + public InboundsService inbounds() { + if (null == this.inbounds) { + this.inbounds = new InboundsService(uriUUID, context, httpClient, authManagers); + } + return this.inbounds; + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java new file mode 100644 index 000000000..d3100622d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java @@ -0,0 +1,7 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.InboundInternalImpl; + +@JsonDeserialize(using = InboundInternalImpl.Deserializer.class) +public interface InboundMessage {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java new file mode 100644 index 000000000..5f433bbbe --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java @@ -0,0 +1,54 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.InboundsService; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +public class ListInboundsResponse extends ListResponse { + + private final Page page; + private final InboundsService service; + private ListInboundsResponse nextPage; + + public ListInboundsResponse( + InboundsService service, + Page page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + + if (null == nextPage) { + ListInboundMessagesQueryParameters.Builder newParameters = + ListInboundMessagesQueryParameters.builder(page.getParameters()); + newParameters.setPage(page.getNextPageToken()); + nextPage = service.list(newParameters.build()); + } + return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); + } + + public ListInboundsResponse nextPage() { + + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + + ListInboundsResponse response = nextPage; + nextPage = null; + return response; + } + + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "ListInboundsResponse{" + "page=" + page + '}'; + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java new file mode 100644 index 000000000..60370e45c --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java @@ -0,0 +1,162 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; +import com.sinch.sdk.domains.sms.models.v1.inbounds.BinaryMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; +import com.sinch.sdk.models.SmsContext; +import java.time.Instant; +import java.util.Iterator; +import java.util.Map; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +@TestWithResources +class InboundsServiceTest extends BaseTest { + + @Mock SmsContext context; + @Mock HttpClient httpClient; + @Mock Map authManagers; + @Mock InboundsApi api; + InboundsService service; + + String uriPartID = "foovalue"; + + @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + InboundMessage binary; + + @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + InboundMessage text; + + @GivenJsonResource("/domains/sms/v1/inbounds/MOMediaDto.json") + InboundMessage media; + + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") + ApiInboundList inboundsLisResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json") + ApiInboundList inboundsLisResponseDtoPage1; + + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json") + ApiInboundList inboundsLisResponseDtoPage2; + + @BeforeEach + public void initMocks() { + service = spy(new InboundsService(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @Test + void getBinary() throws ApiException { + + when(api.get(eq("foo inbound ID"))).thenReturn(binary); + + InboundMessage response = service.get("foo inbound ID"); + + TestHelpers.recursiveEquals(response, binary); + } + + @Test + void getText() throws ApiException { + + when(api.get(eq("foo inbound ID"))).thenReturn(text); + + InboundMessage response = service.get("foo inbound ID"); + + TestHelpers.recursiveEquals(response, text); + } + + @Test + void getMedia() throws ApiException { + + when(api.get(eq("foo inbound ID"))).thenReturn(media); + + InboundMessage response = service.get("foo inbound ID"); + + TestHelpers.recursiveEquals(response, media); + } + + @Test + void list() throws ApiException { + + ListInboundMessagesQueryParameters initialRequest = + ListInboundMessagesQueryParameters.builder().build(); + ListInboundMessagesQueryParameters page1 = + ListInboundMessagesQueryParameters.builder().setPage(1).build(); + ListInboundMessagesQueryParameters page2 = + ListInboundMessagesQueryParameters.builder().setPage(2).build(); + + when(api.list(initialRequest)).thenReturn(inboundsLisResponseDtoPage0); + when(api.list(page1)).thenReturn(inboundsLisResponseDtoPage1); + when(api.list(page2)).thenReturn(inboundsLisResponseDtoPage2); + + ListInboundsResponse response = service.list(initialRequest); + + Iterator iterator = response.iterator(); + InboundMessage item = iterator.next(); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + BinaryMessage.builder() + .setBody("a body") + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setUdh("foo udh") + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + TextMessage.builder() + .setBody("a body") + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + Assertions.assertThat(item) + .usingRecursiveComparison() + .isEqualTo( + BinaryMessage.builder() + .setBody("a body") + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setUdh("foo udh") + .build()); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java new file mode 100644 index 000000000..17d63616f --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java @@ -0,0 +1,141 @@ +package com.sinch.sdk.domains.sms.api.v1.internal; + +import static org.mockito.ArgumentMatchers.argThat; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +@TestWithResources +public class InboundsApiTest extends BaseTest { + + static final String SMS_AUTH_NAMES = "BearerAuth"; + + @GivenTextResource("/domains/sms/v1/inbounds/MOTextDto.json") + String jsonTextMessageDto; + + @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + TextMessage textMessageDto; + + @GivenTextResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") + String jsonInboundsListResponseDto; + + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") + ApiInboundList listInboundsListResponseDto; + + @Mock HttpClient httpClient; + @Mock ServerConfiguration serverConfiguration; + + HttpMapper httpMapper = new HttpMapper(); + @Mock Map authManagers; + InboundsApi api; + String uriPartID = "foovalue"; + + @BeforeEach + public void initMocks() { + api = + spy(new InboundsApi(httpClient, serverConfiguration, authManagers, httpMapper, uriPartID)); + } + + @Test + void get() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/inbounds/foo%20binary%20batch%20id", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextMessageDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + InboundMessage response = api.get("foo binary batch id"); + + TestHelpers.recursiveEquals(response, textMessageDto); + } + + @Test + void list() throws ApiException { + + Collection urlParameters = + Arrays.asList( + new URLParameter("page", 1, STYLE.FORM, true), + new URLParameter("page_size", 2, STYLE.FORM, true), + new URLParameter("to", "+1234567890", STYLE.FORM, true), + new URLParameter("start_date", "2023-11-03T15:21:21.113Z", STYLE.FORM, true), + new URLParameter("end_date", "2023-12-12T15:54:21.321Z", STYLE.FORM, true), + new URLParameter("client_reference", "client reference", STYLE.FORM, true)); + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/inbounds", + HttpMethod.GET, + urlParameters, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonInboundsListResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + ListInboundMessagesQueryParameters initialRequest = + ListInboundMessagesQueryParameters.builder() + .setPage(1) + .setPageSize(2) + .setTo(Arrays.asList("+1234567890")) + .setClientReference("client reference") + .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) + .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) + .build(); + + ApiInboundList response = api.list(initialRequest); + + TestHelpers.recursiveEquals(response, listInboundsListResponseDto); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/InboundsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/InboundsSteps.java new file mode 100644 index 000000000..0a0311438 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/InboundsSteps.java @@ -0,0 +1,113 @@ +package com.sinch.sdk.e2e.domains.sms.v1; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.api.v1.InboundsService; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.Arrays; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class InboundsSteps { + + InboundsService service; + InboundMessage getResponse; + ListInboundsResponse listOnePageResponse; + ListInboundsResponse listAllResponse; + ListInboundsResponse listAllByPageResponse; + + @Given("^the SMS service \"Inbounds\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().v1().inbounds(); + } + + @When("^I send a request to retrieve an inbound message") + public void get() { + + getResponse = service.get("inboundid"); + } + + @When("^I send a request to list the inbound messages$") + public void listOnePage() { + ListInboundMessagesQueryParameters request = + ListInboundMessagesQueryParameters.builder() + .setTo(Arrays.asList("12017777777", "12018888888")) + .setPageSize(2) + .build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the inbound messages$") + public void listAll() { + ListInboundMessagesQueryParameters request = + ListInboundMessagesQueryParameters.builder() + .setTo(Arrays.asList("12017777777", "12018888888")) + .setPageSize(2) + .build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the inbound messages pages$") + public void listAllByPage() { + ListInboundMessagesQueryParameters request = + ListInboundMessagesQueryParameters.builder() + .setTo(Arrays.asList("12017777777", "12018888888")) + .setPageSize(2) + .build(); + + listAllByPageResponse = service.list(request); + } + + @Then("the response contains the inbound message details") + public void getResult() { + TextMessage expected = + TextMessage.builder() + .setBody("Hello John!") + .setFrom("12015555555") + .setId("01W4FFL35P4NC4K35INBOUND01") + .setOperatorId("311071") + .setReceivedAt(Instant.parse("2024-06-06T14:16:54.777Z")) + .setTo("12017777777") + .build(); + + TestHelpers.recursiveEquals(getResponse, expected); + } + + @Then("the response contains \"{int}\" inbound messages") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the inbound messages list contains \"{int}\" inbound messages") + public void listAllResult(int expected) { + ListInboundsResponse response = + null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the inbound messages iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java index 4229a2763..4519cbf52 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java @@ -12,5 +12,6 @@ @SuiteDisplayName("SMS V1") @IncludeEngines("cucumber") @SelectClasspathResource("features/sms/batches.feature") +@SelectClasspathResource("features/sms/inbounds.feature") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v1") public class SmsIT {} diff --git a/core/src/main/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializer.java b/core/src/main/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializer.java new file mode 100644 index 000000000..3255642b2 --- /dev/null +++ b/core/src/main/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializer.java @@ -0,0 +1,27 @@ +package com.sinch.sdk.core.databind.query_parameter; + +import com.sinch.sdk.core.databind.QueryParameterSerializer; +import java.util.Collection; + +public class CollectionStringToCommaSerializer + implements QueryParameterSerializer, String> { + + public static CollectionStringToCommaSerializer getInstance() { + return CollectionStringToCommaSerializer.LazyHolder.INSTANCE; + } + + @Override + public String apply(Collection collection) { + if (null == collection) { + return null; + } + return String.join(",", collection); + } + + private static class LazyHolder { + private static final CollectionStringToCommaSerializer INSTANCE = + new CollectionStringToCommaSerializer(); + } + + private CollectionStringToCommaSerializer() {} +} diff --git a/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java b/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java index 1381407a5..b41c9fd92 100644 --- a/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java +++ b/core/src/main/com/sinch/sdk/core/databind/query_parameter/InstantToIso8601Serializer.java @@ -22,5 +22,4 @@ private static class LazyHolder { } private InstantToIso8601Serializer() {} - ; } diff --git a/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializerTest.java b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializerTest.java new file mode 100644 index 000000000..d90add527 --- /dev/null +++ b/core/src/test/java/com/sinch/sdk/core/databind/query_parameter/CollectionStringToCommaSerializerTest.java @@ -0,0 +1,49 @@ +package com.sinch.sdk.core.databind.query_parameter; + +import com.sinch.sdk.core.TestHelpers; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +class CollectionStringToCommaSerializerTest { + + CollectionStringToCommaSerializer serializer = CollectionStringToCommaSerializer.getInstance(); + + @Test + void serialize() { + + List list = Arrays.asList("foo1", "foo2"); + + String serialized = serializer.apply(list); + + TestHelpers.recursiveEquals("foo1,foo2", serialized); + } + + @Test + void serializeSingle() { + + List list = Collections.singletonList("foo1"); + + String serialized = serializer.apply(list); + + TestHelpers.recursiveEquals("foo1", serialized); + } + + @Test + void serializeEmpty() { + + String serialized = serializer.apply(Collections.emptyList()); + + Assertions.assertEquals("", serialized); + } + + @Test + void serializeNull() { + + String serialized = serializer.apply(null); + + Assertions.assertNull(serialized); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java new file mode 100644 index 000000000..a0abda168 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java @@ -0,0 +1,89 @@ +package com.sinch.sdk.domains.sms.models.v1.inbounds; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import java.time.Instant; +import java.util.Arrays; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; + +@TestWithResources +class InboundMessageDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + InboundMessage loadedBinaryMessage; + + @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + InboundMessage loadedTextMessage; + + @GivenJsonResource("/domains/sms/v1/inbounds/MOMediaDto.json") + InboundMessage loadedMediaMessage; + + BinaryMessage binaryDTO = + BinaryMessage.builder() + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setBody("a body") + .setUdh("foo udh") + .build(); + + TextMessage textDTO = + TextMessage.builder() + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setBody("a body") + .build(); + + MediaMessage mediaDTO = + MediaMessage.builder() + .setClientReference("a client reference") + .setFrom("+11203494390") + .setId("01FC66621XXXXX119Z8PMV1QPA") + .setOperatorId("35000") + .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) + .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) + .setTo("11203453453") + .setBody( + MediaMessageBody.builder() + .setMessage("my message") + .setSubject("mmy subject") + .setMedia( + Arrays.asList( + MediaMessageBodyDetails.builder() + .setCode(1234) + .setContentType("content/type") + .setStatus("a status") + .setUrl("https://foo.url") + .build())) + .build()) + .build(); + + @Test + void deserializeBinaryMessage() { + + Assertions.assertThat(loadedBinaryMessage).usingRecursiveComparison().isEqualTo(binaryDTO); + } + + @Test + void deserializeTextMessage() { + + Assertions.assertThat(loadedTextMessage).usingRecursiveComparison().isEqualTo(textDTO); + } + + @Test + void deserializeMediaMessage() { + + Assertions.assertThat(loadedMediaMessage).usingRecursiveComparison().isEqualTo(mediaDTO); + } +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOMediaDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOMediaDto.json new file mode 100644 index 000000000..36459ad86 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOMediaDto.json @@ -0,0 +1,22 @@ +{ + "body": { + "subject": "mmy subject", + "message": "my message", + "media": [ + { + "url": "https://foo.url", + "contentType": "content/type", + "status": "a status", + "code": 1234 + } + ] + }, + "client_reference": "a client reference", + "from": "+11203494390", + "id": "01FC66621XXXXX119Z8PMV1QPA", + "operator_id": "35000", + "received_at": "2019-08-24T14:17:22Z", + "sent_at": "2019-08-24T14:15:22Z", + "to": "11203453453", + "type": "mo_media" +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/Get.java new file mode 100644 index 000000000..ad35bd616 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/Get.java @@ -0,0 +1,35 @@ +package com.sinch.sample.sms.v1.inbounds; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.InboundsService; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = + Logger.getLogger(com.sinch.sample.sms.deliveryReports.Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + InboundsService service = client.sms().v1().inbounds(); + + String inboundId = "01JFFMTMJ1AY6TAYEPDR4CYG3S"; + LOGGER.info("Get for: " + inboundId); + + InboundMessage response = service.get(inboundId); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/List.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/List.java new file mode 100644 index 000000000..267b48f43 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/inbounds/List.java @@ -0,0 +1,41 @@ +package com.sinch.sample.sms.v1.inbounds; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.InboundsService; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import java.io.IOException; +import java.time.Instant; +import java.time.Period; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + InboundsService service = client.sms().v1().inbounds(); + + LOGGER.info("List inbounds"); + + ListInboundMessagesQueryParameters queryParameters = + ListInboundMessagesQueryParameters.builder() + .setPageSize(1) + .setStartDate(Instant.now().minus(Period.ofWeeks(3))) + .build(); + + LOGGER.info("Response:"); + service.list(queryParameters).iterator().forEachRemaining(f -> LOGGER.info(f.toString())); + } +} From 43dcbaac24197972af5ba78425a06d801f5de9ab Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 2 Jan 2025 12:08:49 +0100 Subject: [PATCH 34/65] test (SMS/Inbounds): Refactor test file names --- .../sinch/sdk/domains/sms/adapters/InboundsServiceTest.java | 4 ++-- .../sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java | 4 ++-- .../domains/sms/api/v1/adapters/InboundsServiceTest.java | 6 +++--- .../sdk/domains/sms/api/v1/internal/InboundsApiTest.java | 4 ++-- .../sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java | 4 ++-- .../sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java | 4 ++-- .../sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java | 4 ++-- .../sms/models/v1/inbounds/InboundMessageDtoTest.java | 6 +++--- .../v1/inbounds/{MOBinaryDto.json => InboundBinaryDto.json} | 0 .../v1/inbounds/{MOMediaDto.json => InboundMediaDto.json} | 0 .../sms/v1/inbounds/{MOTextDto.json => InboundTextDto.json} | 0 11 files changed, 18 insertions(+), 18 deletions(-) rename openapi-contracts/src/test/resources/domains/sms/v1/inbounds/{MOBinaryDto.json => InboundBinaryDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/inbounds/{MOMediaDto.json => InboundMediaDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/inbounds/{MOTextDto.json => InboundTextDto.json} (100%) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java index 9d094bfe7..bc3816cd3 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/InboundsServiceTest.java @@ -40,10 +40,10 @@ class InboundsServiceTest extends BaseTest { String uriPartID = "foovalue"; - @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") InboundDto binary; - @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") InboundDto text; @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java index 1e863089e..d46c98150 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java @@ -28,10 +28,10 @@ @TestWithResources public class WebHooksServiceTest extends BaseTest { - @GivenTextResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") String incomingSMSBinaryJsonString; - @GivenTextResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") String incomingSMSTextJsonString; @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java index 60370e45c..5f0d585a2 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java @@ -39,13 +39,13 @@ class InboundsServiceTest extends BaseTest { String uriPartID = "foovalue"; - @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") InboundMessage binary; - @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") InboundMessage text; - @GivenJsonResource("/domains/sms/v1/inbounds/MOMediaDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundMediaDto.json") InboundMessage media; @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java index 17d63616f..bb31e10ed 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java @@ -40,10 +40,10 @@ public class InboundsApiTest extends BaseTest { static final String SMS_AUTH_NAMES = "BearerAuth"; - @GivenTextResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") String jsonTextMessageDto; - @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") TextMessage textMessageDto; @GivenTextResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java index 83b73b8d9..5829d054b 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/InboundDtoTest.java @@ -10,10 +10,10 @@ @TestWithResources class InboundDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") InboundDto loadedBinaryMessage; - @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") InboundDto loadedTextMessage; MOBinaryDto binaryDTO = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java index 6cea5b357..80b24fb3c 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOBinaryDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources public class MOBinaryDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") MOBinaryDto loadedDto; - @GivenTextResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") String jsonStringDto; public static MOBinaryDto dto = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java index 917f554c5..94bc2ae8a 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/MOTextDtoTest.java @@ -14,10 +14,10 @@ @TestWithResources public class MOTextDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") MOTextDto loadedDto; - @GivenTextResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") String jsonStringDto; public static MOTextDto dto = diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java index a0abda168..0340ec5ac 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java @@ -11,13 +11,13 @@ @TestWithResources class InboundMessageDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/inbounds/MOBinaryDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") InboundMessage loadedBinaryMessage; - @GivenJsonResource("/domains/sms/v1/inbounds/MOTextDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") InboundMessage loadedTextMessage; - @GivenJsonResource("/domains/sms/v1/inbounds/MOMediaDto.json") + @GivenJsonResource("/domains/sms/v1/inbounds/InboundMediaDto.json") InboundMessage loadedMediaMessage; BinaryMessage binaryDTO = diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOBinaryDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/InboundBinaryDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOBinaryDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/InboundBinaryDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOMediaDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/InboundMediaDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOMediaDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/InboundMediaDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOTextDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/inbounds/InboundTextDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/inbounds/MOTextDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/inbounds/InboundTextDto.json From 238d5b620e0f178682472b11810d3c7d149cedcc Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 3 Jan 2025 10:41:06 +0100 Subject: [PATCH 35/65] test (SMS/DeliveryReports): Refactor V0 test resources --- .../adapters/DeliveryReportsServiceTest.java | 17 ++++++++++------- .../sms/adapters/WebHooksServiceTest.java | 8 ++++---- .../DeliveryReportBatchDtoConverterTest.java | 4 ++-- .../dto/v1/DeliveryReportBatchDtoTest.java | 10 ++++++---- .../dto/v1/DeliveryReportRecipientDtoTest.java | 4 ++-- .../BatchDeliveryReportMMSDto.json} | 3 ++- .../BatchDeliveryReportSMSDto.json} | 3 ++- .../RecipientDeliveryReportMMSDto.json} | 0 .../RecipientDeliveryReportSMSDto.json} | 0 .../ListDeliveryReportResponseDtoPage0.json | 0 .../ListDeliveryReportResponseDtoPage1.json | 0 .../ListDeliveryReportResponseDtoPage2.json | 0 12 files changed, 28 insertions(+), 21 deletions(-) rename openapi-contracts/src/test/resources/domains/sms/v1/{DeliveryReportBatchMMSDto.json => deliveryreports/BatchDeliveryReportMMSDto.json} (76%) rename openapi-contracts/src/test/resources/domains/sms/v1/{DeliveryReportBatchSMSDto.json => deliveryreports/BatchDeliveryReportSMSDto.json} (76%) rename openapi-contracts/src/test/resources/domains/sms/v1/{DeliveryReportRecipientMMSDto.json => deliveryreports/RecipientDeliveryReportMMSDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{DeliveryReportRecipientSMSDto.json => deliveryreports/RecipientDeliveryReportSMSDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => deliveryreports/response}/ListDeliveryReportResponseDtoPage0.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => deliveryreports/response}/ListDeliveryReportResponseDtoPage1.json (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{ => deliveryreports/response}/ListDeliveryReportResponseDtoPage2.json (100%) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java index dde863784..b82028ca0 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/DeliveryReportsServiceTest.java @@ -50,25 +50,28 @@ class DeliveryReportsServiceTest extends BaseTest { DeliveryReportsService service; String uriPartID = "foovalue"; - @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") DeliveryReportDto deliveryReportBatchSMSDto; - @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") DeliveryReportDto deliveryReportBatchMMSDto; - @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") RecipientDeliveryReportDto deliveryReportRecipientSMSDto; - @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientMMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") RecipientDeliveryReportDto deliveryReportRecipientMMSDto; - @GivenJsonResource("/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json") + @GivenJsonResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage0.json") DeliveryReportListDto listDeliveryReportResponseDtoPage0; - @GivenJsonResource("/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json") + @GivenJsonResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage1.json") DeliveryReportListDto listDeliveryReportResponseDtoPage1; - @GivenJsonResource("/domains/sms/v1/ListDeliveryReportResponseDtoPage2.json") + @GivenJsonResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage2.json") DeliveryReportListDto listDeliveryReportResponseDtoPage2; @BeforeEach diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java index d46c98150..5a3fbcb0f 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/WebHooksServiceTest.java @@ -34,16 +34,16 @@ public class WebHooksServiceTest extends BaseTest { @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") String incomingSMSTextJsonString; - @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") + @GivenTextResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") String deliveryReportRecipientSMSJsonString; - @GivenTextResource("/domains/sms/v1/DeliveryReportRecipientMMSDto.json") + @GivenTextResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") String deliveryReportRecipientMMSJsonString; - @GivenTextResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + @GivenTextResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") String deliveryReportBatchSMSJsonString; - @GivenTextResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + @GivenTextResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") String deliveryReportBatchMMSJsonString; @InjectMocks WebHooksService service; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java index 789d6416d..cbfd8a515 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/DeliveryReportBatchDtoConverterTest.java @@ -22,10 +22,10 @@ @TestWithResources class DeliveryReportBatchDtoConverterTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") DeliveryReportDto deliveryReportSMSClientDto; - @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") DeliveryReportDto deliveryReportMMSClientDto; public static void compareWithDto( diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java index 8966cfeec..fb2a8863d 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportBatchDtoTest.java @@ -10,10 +10,10 @@ @TestWithResources public class DeliveryReportBatchDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchSMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") DeliveryReportDto deliveryReportBatchSMSDto; - @GivenJsonResource("/domains/sms/v1/DeliveryReportBatchMMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") DeliveryReportDto deliveryReportBatchMMSDto; public static DeliveryReportDto deliveryReportBatchSMS = @@ -26,7 +26,8 @@ public class DeliveryReportBatchDtoTest extends BaseTest { .count(1) .addRecipientsItem("44231235674") .status("Delivered"))) - .totalMessageCount(1); + .totalMessageCount(1) + .clientReference("a client reference"); public static DeliveryReportDto deliveryReportBatchMMS = new DeliveryReportDto("01FC66621XXXXX119Z8PMV1QPQ") @@ -38,7 +39,8 @@ public class DeliveryReportBatchDtoTest extends BaseTest { .count(1) .addRecipientsItem("44231235674") .status("Delivered"))) - .totalMessageCount(1); + .totalMessageCount(1) + .clientReference("a client reference"); @Test void deserializeDeliveryReportBatchSMS() { diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java index 690b26ce1..c83f8e41a 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/DeliveryReportRecipientDtoTest.java @@ -10,10 +10,10 @@ @TestWithResources public class DeliveryReportRecipientDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientSMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") RecipientDeliveryReportDto deliveryReportRecipientSMSDto; - @GivenJsonResource("/domains/sms/v1/DeliveryReportRecipientMMSDto.json") + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") RecipientDeliveryReportDto deliveryReportRecipientMMSDto; public static RecipientDeliveryReportDto deliveryReportRecipientSMS = diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportBatchMMSDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json similarity index 76% rename from openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportBatchMMSDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json index a1bf13389..361260b4b 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportBatchMMSDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json @@ -11,5 +11,6 @@ "status": "Delivered" } ], - "total_message_count": 1 + "total_message_count": 1, + "client_reference": "a client reference" } \ No newline at end of file diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportBatchSMSDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json similarity index 76% rename from openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportBatchSMSDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json index f35d84e42..8162a5391 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportBatchSMSDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json @@ -11,5 +11,6 @@ "status": "Delivered" } ], - "total_message_count": 1 + "total_message_count": 1, + "client_reference": "a client reference" } \ No newline at end of file diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportRecipientMMSDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportRecipientMMSDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportRecipientSMSDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/DeliveryReportRecipientSMSDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage0.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage0.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage0.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage1.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage1.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage1.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage2.json b/openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage2.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/ListDeliveryReportResponseDtoPage2.json rename to openapi-contracts/src/test/resources/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage2.json From dde0acbb530b68318b5743b67e374dcd96c55e5d Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 6 Jan 2025 10:01:07 +0100 Subject: [PATCH 36/65] refactor (SMS/Pagination): Sharing 'SMSCursorPageNavigator' as internal --- .../sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java | 2 +- .../sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java | 2 +- .../v1/{batches => }/internal/SMSCursorPageNavigator.java | 2 +- .../sms/models/v1/internal/SMSCursorPageNavigatorTest.java | 1 - 4 files changed, 3 insertions(+), 4 deletions(-) rename client/src/main/com/sinch/sdk/domains/sms/models/v1/{batches => }/internal/SMSCursorPageNavigator.java (92%) diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java index cad456982..76879511f 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java @@ -6,7 +6,6 @@ import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; -import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; @@ -16,6 +15,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; import com.sinch.sdk.models.SmsContext; import java.util.Map; diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java index 831fa3592..4fae304ca 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java @@ -6,11 +6,11 @@ import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; -import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; import com.sinch.sdk.models.SmsContext; import java.util.Map; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigator.java similarity index 92% rename from client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java rename to client/src/main/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigator.java index 7e43e2c67..1075d0ab0 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/internal/SMSCursorPageNavigator.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigator.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.sms.models.v1.batches.internal; +package com.sinch.sdk.domains.sms.models.v1.internal; import com.sinch.sdk.core.models.pagination.PageNavigator; diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java index aafa8b01e..521cd1453 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/models/v1/internal/SMSCursorPageNavigatorTest.java @@ -1,6 +1,5 @@ package com.sinch.sdk.domains.sms.models.v1.internal; -import com.sinch.sdk.domains.sms.models.v1.batches.internal.SMSCursorPageNavigator; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; From 57f4ecc60e147dd329049df063492e3ab31ec176 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 6 Jan 2025 10:03:10 +0100 Subject: [PATCH 37/65] fix (SMS/Pagination.hasNextPage): Prevent unnecessary 'nextPage' call if current page content is empty --- .../sms/models/v1/batches/response/ListBatchesResponse.java | 3 +++ .../sms/models/v1/inbounds/response/ListInboundsResponse.java | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java index 02bd716fa..1a99f689b 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java @@ -21,6 +21,9 @@ public ListBatchesResponse( public boolean hasNextPage() { + if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { + return false; + } if (null == nextPage) { ListBatchesQueryParameters.Builder newParameters = ListBatchesQueryParameters.builder(page.getParameters()); diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java index 5f433bbbe..5aac7b2f9 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java @@ -23,6 +23,10 @@ public ListInboundsResponse( public boolean hasNextPage() { + if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { + return false; + } + if (null == nextPage) { ListInboundMessagesQueryParameters.Builder newParameters = ListInboundMessagesQueryParameters.builder(page.getParameters()); From 9a68f9bcdee4816bdfcab192c4260940126db2bb Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 3 Jan 2025 10:45:11 +0100 Subject: [PATCH 38/65] feat (SMS/DeliveryReports): Generated files --- .../api/v1/internal/DeliveryReportsApi.java | 363 ++++++++++++++ .../BatchDeliveryReportMMS.java | 108 +++++ .../BatchDeliveryReportMMSImpl.java | 223 +++++++++ .../BatchDeliveryReportSMS.java | 108 +++++ .../BatchDeliveryReportSMSImpl.java | 223 +++++++++ .../DeliveryReceiptErrorCode.java | 153 ++++++ .../v1/deliveryreports/DeliveryStatus.java | 81 ++++ .../v1/deliveryreports/EncodingType.java | 33 ++ .../MessageDeliveryStatus.java | 108 +++++ .../MessageDeliveryStatusImpl.java | 175 +++++++ .../RecipientDeliveryReportMMS.java | 227 +++++++++ .../RecipientDeliveryReportMMSImpl.java | 441 ++++++++++++++++++ .../RecipientDeliveryReportSMS.java | 227 +++++++++ .../RecipientDeliveryReportSMSImpl.java | 441 ++++++++++++++++++ .../internal/BatchDeliveryReportOneOf.java | 17 + .../BatchDeliveryReportOneOfImpl.java | 337 +++++++++++++ .../RecipientDeliveryReportOneOf.java | 17 + .../RecipientDeliveryReportOneOfImpl.java | 353 ++++++++++++++ .../BatchDeliveryReportQueryParameters.java | 97 ++++ ...atchDeliveryReportQueryParametersImpl.java | 115 +++++ .../ListDeliveryReportsQueryParameters.java | 162 +++++++ ...istDeliveryReportsQueryParametersImpl.java | 181 +++++++ .../request/QueryReportType.java | 36 ++ .../response/internal/DeliveryReportList.java | 104 +++++ .../internal/DeliveryReportListImpl.java | 176 +++++++ 25 files changed, 4506 insertions(+) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMS.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMSImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMS.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMSImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReceiptErrorCode.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryStatus.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatus.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatusImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMS.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMSImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMS.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMSImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOf.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOfImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOf.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOfImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParameters.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParametersImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParameters.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParametersImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/QueryReportType.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java new file mode 100644 index 000000000..c84ab9bfe --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java @@ -0,0 +1,363 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1.internal; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.HttpStatus; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameterUtils; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal.DeliveryReportList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +public class DeliveryReportsApi { + + private static final Logger LOGGER = Logger.getLogger(DeliveryReportsApi.class.getName()); + private HttpClient httpClient; + private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; + private HttpMapper mapper; + + private final String servicePlanId; + + public DeliveryReportsApi( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper, + String servicePlanId) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + this.servicePlanId = servicePlanId; + } + + /** + * Retrieve a delivery report Delivery reports can be retrieved even if no callback was requested. + * The difference between a summary and a full report is only that the full report contains the + * phone numbers in [>E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537\") + * format for each status code. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param queryParameter (optional) + * @return BatchDeliveryReport + * @throws ApiException if fails to make API call + */ + public BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters queryParameter) + throws ApiException { + + LOGGER.finest( + "[get]" + " " + "batchId: " + batchId + ", " + "queryParameter: " + queryParameter); + + HttpRequest httpRequest = getRequestBuilder(batchId, queryParameter); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = + new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest getRequestBuilder( + String batchId, BatchDeliveryReportQueryParameters queryParameter) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling get"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException(400, "Missing the required parameter 'batchId' when calling get"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}/delivery_report" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getType(), "type", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getStatus(), + "status", + URLParameter.form, + null, + localVarQueryParams, + false); + + URLParameterUtils.addQueryParam( + queryParameter.getCode(), "code", URLParameter.form, null, localVarQueryParams, false); + } + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Retrieve a recipient delivery report A recipient delivery report contains the message status + * for a single recipient phone number. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param recipientMsisdn Phone number for which you to want to search. (required) + * @return RecipientDeliveryReport + * @throws ApiException if fails to make API call + */ + public RecipientDeliveryReport getForNumber(String batchId, String recipientMsisdn) + throws ApiException { + + LOGGER.finest( + "[getForNumber]" + + " " + + "batchId: " + + batchId + + ", " + + "recipientMsisdn: " + + recipientMsisdn); + + HttpRequest httpRequest = getForNumberRequestBuilder(batchId, recipientMsisdn); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = + new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest getForNumberRequestBuilder(String batchId, String recipientMsisdn) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling getForNumber"); + } + // verify the required parameter 'batchId' is set + if (batchId == null) { + throw new ApiException( + 400, "Missing the required parameter 'batchId' when calling getForNumber"); + } + // verify the required parameter 'recipientMsisdn' is set + if (recipientMsisdn == null) { + throw new ApiException( + 400, "Missing the required parameter 'recipientMsisdn' when calling getForNumber"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/batches/{batch_id}/delivery_report/{recipient_msisdn}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "batch_id" + "\\}", URLPathUtils.encodePathSegment(batchId.toString())) + .replaceAll( + "\\{" + "recipient_msisdn" + "\\}", + URLPathUtils.encodePathSegment(recipientMsisdn.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Retrieve a list of delivery reports Get a list of finished delivery reports. This operation + * supports pagination. + * + * @param queryParameter (optional) + * @return DeliveryReportList + * @throws ApiException if fails to make API call + */ + public DeliveryReportList list(ListDeliveryReportsQueryParameters queryParameter) + throws ApiException { + + LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); + + HttpRequest httpRequest = listRequestBuilder(queryParameter); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = + new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest listRequestBuilder(ListDeliveryReportsQueryParameters queryParameter) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling list"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/delivery_reports" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPage(), "page", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getPageSize(), + "page_size", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getStartDate(), + "start_date", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getEndDate(), + "end_date", + URLParameter.form, + null, + localVarQueryParams, + true); + + URLParameterUtils.addQueryParam( + queryParameter.getStatus(), + "status", + URLParameter.form, + null, + localVarQueryParams, + false); + + URLParameterUtils.addQueryParam( + queryParameter.getCode(), "code", URLParameter.form, null, localVarQueryParams, false); + + URLParameterUtils.addQueryParam( + queryParameter.getClientReference(), + "client_reference", + URLParameter.form, + null, + localVarQueryParams, + true); + } + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMS.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMS.java new file mode 100644 index 000000000..a1d6488b6 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMS.java @@ -0,0 +1,108 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; + +/** BatchDeliveryReportMMS */ +@JsonDeserialize(builder = BatchDeliveryReportMMSImpl.Builder.class) +public interface BatchDeliveryReportMMS extends BatchDeliveryReport { + + /** + * The ID of the batch this delivery report belongs to. + * + * @return batchId + * @readOnly This field is returned by the server and cannot be modified + */ + String getBatchId(); + + /** + * The client identifier of the batch this delivery report belongs to, if set when submitting + * batch. + * + * @return clientReference + */ + String getClientReference(); + + /** + * Array with status objects. Only status codes with at least one recipient will be listed. + * + * @return statuses + */ + List getStatuses(); + + /** + * The total number of messages in the batch. + * + *

minimum: 0 + * + * @return totalMessageCount + */ + Integer getTotalMessageCount(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BatchDeliveryReportMMSImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param batchId see getter + * @return Current builder + * @see #getBatchId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setBatchId(String batchId); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param statuses see getter + * @return Current builder + * @see #getStatuses + */ + Builder setStatuses(List statuses); + + /** + * see getter + * + * @param totalMessageCount see getter + * @return Current builder + * @see #getTotalMessageCount + */ + Builder setTotalMessageCount(Integer totalMessageCount); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BatchDeliveryReportMMS build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMSImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMSImpl.java new file mode 100644 index 000000000..1af8ece7d --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportMMSImpl.java @@ -0,0 +1,223 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; + +@JsonPropertyOrder({ + BatchDeliveryReportMMSImpl.JSON_PROPERTY_BATCH_ID, + BatchDeliveryReportMMSImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BatchDeliveryReportMMSImpl.JSON_PROPERTY_STATUSES, + BatchDeliveryReportMMSImpl.JSON_PROPERTY_TOTAL_MESSAGE_COUNT, + BatchDeliveryReportMMSImpl.JSON_PROPERTY_TYPE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BatchDeliveryReportMMSImpl implements BatchDeliveryReportMMS, BatchDeliveryReport { + private static final long serialVersionUID = 1L; + + /** Gets or Sets type */ + public static class TypeEnum extends EnumDynamic { + public static final TypeEnum DELIVERY_REPORT_MMS = new TypeEnum("delivery_report_mms"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(DELIVERY_REPORT_MMS)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + public static final String JSON_PROPERTY_BATCH_ID = "batch_id"; + + private OptionalValue batchId; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_STATUSES = "statuses"; + + private OptionalValue> statuses; + + public static final String JSON_PROPERTY_TOTAL_MESSAGE_COUNT = "total_message_count"; + + private OptionalValue totalMessageCount; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public BatchDeliveryReportMMSImpl() {} + + protected BatchDeliveryReportMMSImpl( + OptionalValue batchId, + OptionalValue clientReference, + OptionalValue> statuses, + OptionalValue totalMessageCount, + OptionalValue type) { + this.batchId = batchId; + this.clientReference = clientReference; + this.statuses = statuses; + this.totalMessageCount = totalMessageCount; + this.type = type; + } + + @JsonIgnore + public String getBatchId() { + return batchId.orElse(null); + } + + @JsonIgnore + public OptionalValue batchId() { + return batchId; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public List getStatuses() { + return statuses.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STATUSES) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> statuses() { + return statuses; + } + + @JsonIgnore + public Integer getTotalMessageCount() { + return totalMessageCount.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TOTAL_MESSAGE_COUNT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue totalMessageCount() { + return totalMessageCount; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + /** Return true if this BatchDeliveryReportMMS object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BatchDeliveryReportMMSImpl batchDeliveryReportMMS = (BatchDeliveryReportMMSImpl) o; + return Objects.equals(this.batchId, batchDeliveryReportMMS.batchId) + && Objects.equals(this.clientReference, batchDeliveryReportMMS.clientReference) + && Objects.equals(this.statuses, batchDeliveryReportMMS.statuses) + && Objects.equals(this.totalMessageCount, batchDeliveryReportMMS.totalMessageCount) + && Objects.equals(this.type, batchDeliveryReportMMS.type); + } + + @Override + public int hashCode() { + return Objects.hash(batchId, clientReference, statuses, totalMessageCount, type); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BatchDeliveryReportMMSImpl {\n"); + sb.append(" batchId: ").append(toIndentedString(batchId)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" statuses: ").append(toIndentedString(statuses)).append("\n"); + sb.append(" totalMessageCount: ").append(toIndentedString(totalMessageCount)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BatchDeliveryReportMMS.Builder { + OptionalValue batchId = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue> statuses = OptionalValue.empty(); + OptionalValue totalMessageCount = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.DELIVERY_REPORT_MMS); + + @JsonProperty(JSON_PROPERTY_BATCH_ID) + public Builder setBatchId(String batchId) { + this.batchId = OptionalValue.of(batchId); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_STATUSES) + public Builder setStatuses(List statuses) { + this.statuses = OptionalValue.of(statuses); + return this; + } + + @JsonProperty(JSON_PROPERTY_TOTAL_MESSAGE_COUNT) + public Builder setTotalMessageCount(Integer totalMessageCount) { + this.totalMessageCount = OptionalValue.of(totalMessageCount); + return this; + } + + public BatchDeliveryReportMMS build() { + return new BatchDeliveryReportMMSImpl( + batchId, clientReference, statuses, totalMessageCount, type); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMS.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMS.java new file mode 100644 index 000000000..9623ff337 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMS.java @@ -0,0 +1,108 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; + +/** BatchDeliveryReportSMS */ +@JsonDeserialize(builder = BatchDeliveryReportSMSImpl.Builder.class) +public interface BatchDeliveryReportSMS extends BatchDeliveryReport { + + /** + * The ID of the batch this delivery report belongs to. + * + * @return batchId + * @readOnly This field is returned by the server and cannot be modified + */ + String getBatchId(); + + /** + * The client identifier of the batch this delivery report belongs to, if set when submitting + * batch. + * + * @return clientReference + */ + String getClientReference(); + + /** + * Array with status objects. Only status codes with at least one recipient will be listed. + * + * @return statuses + */ + List getStatuses(); + + /** + * The total number of messages in the batch. + * + *

minimum: 0 + * + * @return totalMessageCount + */ + Integer getTotalMessageCount(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BatchDeliveryReportSMSImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param batchId see getter + * @return Current builder + * @see #getBatchId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setBatchId(String batchId); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param statuses see getter + * @return Current builder + * @see #getStatuses + */ + Builder setStatuses(List statuses); + + /** + * see getter + * + * @param totalMessageCount see getter + * @return Current builder + * @see #getTotalMessageCount + */ + Builder setTotalMessageCount(Integer totalMessageCount); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BatchDeliveryReportSMS build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMSImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMSImpl.java new file mode 100644 index 000000000..5e5350e43 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportSMSImpl.java @@ -0,0 +1,223 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.List; +import java.util.Objects; +import java.util.stream.Stream; + +@JsonPropertyOrder({ + BatchDeliveryReportSMSImpl.JSON_PROPERTY_BATCH_ID, + BatchDeliveryReportSMSImpl.JSON_PROPERTY_CLIENT_REFERENCE, + BatchDeliveryReportSMSImpl.JSON_PROPERTY_STATUSES, + BatchDeliveryReportSMSImpl.JSON_PROPERTY_TOTAL_MESSAGE_COUNT, + BatchDeliveryReportSMSImpl.JSON_PROPERTY_TYPE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class BatchDeliveryReportSMSImpl implements BatchDeliveryReportSMS, BatchDeliveryReport { + private static final long serialVersionUID = 1L; + + /** Gets or Sets type */ + public static class TypeEnum extends EnumDynamic { + public static final TypeEnum DELIVERY_REPORT_SMS = new TypeEnum("delivery_report_sms"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(TypeEnum.class, TypeEnum::new, Arrays.asList(DELIVERY_REPORT_SMS)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + public static final String JSON_PROPERTY_BATCH_ID = "batch_id"; + + private OptionalValue batchId; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_STATUSES = "statuses"; + + private OptionalValue> statuses; + + public static final String JSON_PROPERTY_TOTAL_MESSAGE_COUNT = "total_message_count"; + + private OptionalValue totalMessageCount; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public BatchDeliveryReportSMSImpl() {} + + protected BatchDeliveryReportSMSImpl( + OptionalValue batchId, + OptionalValue clientReference, + OptionalValue> statuses, + OptionalValue totalMessageCount, + OptionalValue type) { + this.batchId = batchId; + this.clientReference = clientReference; + this.statuses = statuses; + this.totalMessageCount = totalMessageCount; + this.type = type; + } + + @JsonIgnore + public String getBatchId() { + return batchId.orElse(null); + } + + @JsonIgnore + public OptionalValue batchId() { + return batchId; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public List getStatuses() { + return statuses.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STATUSES) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> statuses() { + return statuses; + } + + @JsonIgnore + public Integer getTotalMessageCount() { + return totalMessageCount.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TOTAL_MESSAGE_COUNT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue totalMessageCount() { + return totalMessageCount; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + /** Return true if this BatchDeliveryReportSMS object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BatchDeliveryReportSMSImpl batchDeliveryReportSMS = (BatchDeliveryReportSMSImpl) o; + return Objects.equals(this.batchId, batchDeliveryReportSMS.batchId) + && Objects.equals(this.clientReference, batchDeliveryReportSMS.clientReference) + && Objects.equals(this.statuses, batchDeliveryReportSMS.statuses) + && Objects.equals(this.totalMessageCount, batchDeliveryReportSMS.totalMessageCount) + && Objects.equals(this.type, batchDeliveryReportSMS.type); + } + + @Override + public int hashCode() { + return Objects.hash(batchId, clientReference, statuses, totalMessageCount, type); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BatchDeliveryReportSMSImpl {\n"); + sb.append(" batchId: ").append(toIndentedString(batchId)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" statuses: ").append(toIndentedString(statuses)).append("\n"); + sb.append(" totalMessageCount: ").append(toIndentedString(totalMessageCount)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements BatchDeliveryReportSMS.Builder { + OptionalValue batchId = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue> statuses = OptionalValue.empty(); + OptionalValue totalMessageCount = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.DELIVERY_REPORT_SMS); + + @JsonProperty(JSON_PROPERTY_BATCH_ID) + public Builder setBatchId(String batchId) { + this.batchId = OptionalValue.of(batchId); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_STATUSES) + public Builder setStatuses(List statuses) { + this.statuses = OptionalValue.of(statuses); + return this; + } + + @JsonProperty(JSON_PROPERTY_TOTAL_MESSAGE_COUNT) + public Builder setTotalMessageCount(Integer totalMessageCount) { + this.totalMessageCount = OptionalValue.of(totalMessageCount); + return this; + } + + public BatchDeliveryReportSMS build() { + return new BatchDeliveryReportSMSImpl( + batchId, clientReference, statuses, totalMessageCount, type); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReceiptErrorCode.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReceiptErrorCode.java new file mode 100644 index 000000000..140bcd008 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReceiptErrorCode.java @@ -0,0 +1,153 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * The delivery report status code provides a more detailed view of what happened with a message. + * The REST API error codes are a combination of SMPP error codes, MMS error codes and custom codes. + */ +public class DeliveryReceiptErrorCode extends EnumDynamic { + + /** + * Queued. Message is queued within REST API system and will be dispatched according to the rate + * of the account. + */ + public static final DeliveryReceiptErrorCode QUEUED = new DeliveryReceiptErrorCode(400); + + /** Dispatched. Message has been dispatched to SMSC. */ + public static final DeliveryReceiptErrorCode DISPATCHED = new DeliveryReceiptErrorCode(401); + + /** Message unroutable. SMSC rejected message. Retrying is likely to cause the same error. */ + public static final DeliveryReceiptErrorCode MESSAGE_UNROUTABLE = + new DeliveryReceiptErrorCode(402); + + /** Internal error. An unexpected error caused the message to fail. */ + public static final DeliveryReceiptErrorCode INTERNAL_ERROR = new DeliveryReceiptErrorCode(403); + + /** + * Temporary delivery. failure` Message failed because of temporary delivery failure. Message can + * be retried. + */ + public static final DeliveryReceiptErrorCode TEMPORARY_DELIVERY_FAILURE = + new DeliveryReceiptErrorCode(404); + + /** + * Unmatched Parameter. One or more parameters in the message body has no mapping for this + * recipient. See Message + * Parameterization + */ + public static final DeliveryReceiptErrorCode UNMATCHED_PARAMETER = + new DeliveryReceiptErrorCode(405); + + /** + * Internal Expiry. Message was expired before reaching SMSC. This may happen if the expiry time + * for the message was very short. + */ + public static final DeliveryReceiptErrorCode INTERNAL_EXPIRY = new DeliveryReceiptErrorCode(406); + + /** Cancelled. Message was cancelled by user before reaching SMSC. */ + public static final DeliveryReceiptErrorCode CANCELLED = new DeliveryReceiptErrorCode(407); + + /** Internal Reject. SMSC rejected the message. Retrying is likely to cause the same error. */ + public static final DeliveryReceiptErrorCode INTERNAL_REJECT = new DeliveryReceiptErrorCode(408); + + /** + * Unmatched default originator. No default originator exists/configured for this recipient when + * sending message without originator. + */ + public static final DeliveryReceiptErrorCode UNMATCHED_DEFAULT_ORIGINATOR = + new DeliveryReceiptErrorCode(410); + + /** + * Exceeded parts limit. Message failed as the number of message parts exceeds the defined max + * number of message parts. + */ + public static final DeliveryReceiptErrorCode EXCEEDED_PARTS_LIMIT = + new DeliveryReceiptErrorCode(411); + + /** + * Unprovisioned region. SMSC rejected the message. The account hasn't been provisioned for this + * region. + */ + public static final DeliveryReceiptErrorCode UNPROVISIONED_REGION = + new DeliveryReceiptErrorCode(412); + + /** Blocked. The account is blocked. Reach out to support for help. Potentially out of credits. */ + public static final DeliveryReceiptErrorCode BLOCKED = new DeliveryReceiptErrorCode(413); + + /** + * Bad Media. MMS only, the request failed due to a bad media URL. It is possible that the URL was + * unreachable, or sent a bad response. + */ + public static final DeliveryReceiptErrorCode BAD_MEDIA = new DeliveryReceiptErrorCode(414); + + /** + * Delivery report Rejected. MMS only, message reached MMSC but was rejected by MMS gateway or + * mobile network. + */ + public static final DeliveryReceiptErrorCode DELIVERY_REPORT_REJECTED = + new DeliveryReceiptErrorCode(415); + + /** Delivery report Not Supported. MMS only, message reached MMSC but it is not supported. */ + public static final DeliveryReceiptErrorCode DELIVERY_REPORT_NOT_SUPPORTED = + new DeliveryReceiptErrorCode(416); + + /** + * Delivery report Unreachable. MMS only, message reached MMSC but the destination network or the + * mobile subscriber cannot be reached. + */ + public static final DeliveryReceiptErrorCode DELIVERY_REPORT_UNREACHABLE = + new DeliveryReceiptErrorCode(417); + + /** + * Delivery report Unrecognized. MMS only, message reached MMSC but the handset of the mobile + * subscriber does not recognize the message content. + */ + public static final DeliveryReceiptErrorCode DELIVERY_REPORT_UNRECOGNIZED = + new DeliveryReceiptErrorCode(418); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + DeliveryReceiptErrorCode.class, + DeliveryReceiptErrorCode::new, + Arrays.asList( + QUEUED, + DISPATCHED, + MESSAGE_UNROUTABLE, + INTERNAL_ERROR, + TEMPORARY_DELIVERY_FAILURE, + UNMATCHED_PARAMETER, + INTERNAL_EXPIRY, + CANCELLED, + INTERNAL_REJECT, + UNMATCHED_DEFAULT_ORIGINATOR, + EXCEEDED_PARTS_LIMIT, + UNPROVISIONED_REGION, + BLOCKED, + BAD_MEDIA, + DELIVERY_REPORT_REJECTED, + DELIVERY_REPORT_NOT_SUPPORTED, + DELIVERY_REPORT_UNREACHABLE, + DELIVERY_REPORT_UNRECOGNIZED)); + + private DeliveryReceiptErrorCode(Integer value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static DeliveryReceiptErrorCode from(Integer value) { + return ENUM_SUPPORT.from(value); + } + + public static Integer valueOf(DeliveryReceiptErrorCode e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryStatus.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryStatus.java new file mode 100644 index 000000000..c69aebc68 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryStatus.java @@ -0,0 +1,81 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** The simplified status as described in Delivery Report Statuses. */ +public class DeliveryStatus extends EnumDynamic { + + /** + * Intermediate type. Message is queued within REST API system and will be dispatched according to + * the rate of the account. + */ + public static final DeliveryStatus QUEUED = new DeliveryStatus("Queued"); + + /** Intermediate type. Message has been dispatched and accepted for delivery by the SMSC. */ + public static final DeliveryStatus DISPATCHED = new DeliveryStatus("Dispatched"); + + /** Final type. Message was aborted before reaching the SMSC. */ + public static final DeliveryStatus ABORTED = new DeliveryStatus("Aborted"); + + /** Final type. Message was cancelled by user before reaching SMSC. */ + public static final DeliveryStatus CANCELLED = new DeliveryStatus("Cancelled"); + + /** Final type. Message failed to be delivered. */ + public static final DeliveryStatus FAILED = new DeliveryStatus("Failed"); + + /** Final type. Message has been delivered. */ + public static final DeliveryStatus DELIVERED = new DeliveryStatus("Delivered"); + + /** + * Final type. Message expired before delivery to the SMSC. This may happen if the expiry time for + * the message was very short. + */ + public static final DeliveryStatus EXPIRED = new DeliveryStatus("Expired"); + + /** Final type. Message was rejected by the SMSC. */ + public static final DeliveryStatus REJECTED = new DeliveryStatus("Rejected"); + + /** Final type. Message was deleted by the SMSC. */ + public static final DeliveryStatus DELETED = new DeliveryStatus("Deleted"); + + /** + * Final type. Message was delivered to the SMSC but no Delivery Receipt has been received or a + * Delivery Receipt that couldn't be interpreted was received. + */ + public static final DeliveryStatus UNKNOWN = new DeliveryStatus("Unknown"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + DeliveryStatus.class, + DeliveryStatus::new, + Arrays.asList( + QUEUED, + DISPATCHED, + ABORTED, + CANCELLED, + FAILED, + DELIVERED, + EXPIRED, + REJECTED, + DELETED, + UNKNOWN)); + + private DeliveryStatus(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static DeliveryStatus from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(DeliveryStatus e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java new file mode 100644 index 000000000..eddb456a8 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java @@ -0,0 +1,33 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Applied encoding for message. Present only if smart encoding is enabled. */ +public class EncodingType extends EnumDynamic { + + public static final EncodingType GSM = new EncodingType("GSM"); + + public static final EncodingType UNICODE = new EncodingType("UNICODE"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>(EncodingType.class, EncodingType::new, Arrays.asList(GSM, UNICODE)); + + private EncodingType(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static EncodingType from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(EncodingType e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatus.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatus.java new file mode 100644 index 000000000..0c41555db --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatus.java @@ -0,0 +1,108 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.Set; + +/** Array with status objects. Only status codes with at least one recipient will be listed. */ +@JsonDeserialize(builder = MessageDeliveryStatusImpl.Builder.class) +public interface MessageDeliveryStatus { + + /** + * The detailed status + * code. + * + * @return code + */ + DeliveryReceiptErrorCode getCode(); + + /** + * The number of messages that currently has this code. + * + *

minimum: 1 + * + * @return count + */ + Integer getCount(); + + /** + * Only for full report. A list of the phone number recipients which messages has + * this status code. + * + * @return recipients + */ + Set getRecipients(); + + /** + * Get status + * + * @return status + */ + DeliveryStatus getStatus(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new MessageDeliveryStatusImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param code see getter + * @return Current builder + * @see #getCode + */ + Builder setCode(DeliveryReceiptErrorCode code); + + /** + * see getter + * + * @param count see getter + * @return Current builder + * @see #getCount + */ + Builder setCount(Integer count); + + /** + * see getter + * + * @param recipients see getter + * @return Current builder + * @see #getRecipients + */ + Builder setRecipients(Set recipients); + + /** + * see getter + * + * @param status see getter + * @return Current builder + * @see #getStatus + */ + Builder setStatus(DeliveryStatus status); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + MessageDeliveryStatus build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatusImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatusImpl.java new file mode 100644 index 000000000..b2bea9108 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/MessageDeliveryStatusImpl.java @@ -0,0 +1,175 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; +import java.util.Set; + +@JsonPropertyOrder({ + MessageDeliveryStatusImpl.JSON_PROPERTY_CODE, + MessageDeliveryStatusImpl.JSON_PROPERTY_COUNT, + MessageDeliveryStatusImpl.JSON_PROPERTY_RECIPIENTS, + MessageDeliveryStatusImpl.JSON_PROPERTY_STATUS +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class MessageDeliveryStatusImpl implements MessageDeliveryStatus { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_CODE = "code"; + + private OptionalValue code; + + public static final String JSON_PROPERTY_COUNT = "count"; + + private OptionalValue count; + + public static final String JSON_PROPERTY_RECIPIENTS = "recipients"; + + private OptionalValue> recipients; + + public static final String JSON_PROPERTY_STATUS = "status"; + + private OptionalValue status; + + public MessageDeliveryStatusImpl() {} + + protected MessageDeliveryStatusImpl( + OptionalValue code, + OptionalValue count, + OptionalValue> recipients, + OptionalValue status) { + this.code = code; + this.count = count; + this.recipients = recipients; + this.status = status; + } + + @JsonIgnore + public DeliveryReceiptErrorCode getCode() { + return code.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue code() { + return code; + } + + @JsonIgnore + public Integer getCount() { + return count.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue count() { + return count; + } + + @JsonIgnore + public Set getRecipients() { + return recipients.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECIPIENTS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue> recipients() { + return recipients; + } + + @JsonIgnore + public DeliveryStatus getStatus() { + return status.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STATUS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue status() { + return status; + } + + /** Return true if this MessageDeliveryStatus object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + MessageDeliveryStatusImpl messageDeliveryStatus = (MessageDeliveryStatusImpl) o; + return Objects.equals(this.code, messageDeliveryStatus.code) + && Objects.equals(this.count, messageDeliveryStatus.count) + && Objects.equals(this.recipients, messageDeliveryStatus.recipients) + && Objects.equals(this.status, messageDeliveryStatus.status); + } + + @Override + public int hashCode() { + return Objects.hash(code, count, recipients, status); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class MessageDeliveryStatusImpl {\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" recipients: ").append(toIndentedString(recipients)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements MessageDeliveryStatus.Builder { + OptionalValue code = OptionalValue.empty(); + OptionalValue count = OptionalValue.empty(); + OptionalValue> recipients = OptionalValue.empty(); + OptionalValue status = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_CODE) + public Builder setCode(DeliveryReceiptErrorCode code) { + this.code = OptionalValue.of(code); + return this; + } + + @JsonProperty(JSON_PROPERTY_COUNT) + public Builder setCount(Integer count) { + this.count = OptionalValue.of(count); + return this; + } + + @JsonProperty(JSON_PROPERTY_RECIPIENTS) + public Builder setRecipients(Set recipients) { + this.recipients = OptionalValue.of(recipients); + return this; + } + + @JsonProperty(JSON_PROPERTY_STATUS) + public Builder setStatus(DeliveryStatus status) { + this.status = OptionalValue.of(status); + return this; + } + + public MessageDeliveryStatus build() { + return new MessageDeliveryStatusImpl(code, count, recipients, status); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMS.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMS.java new file mode 100644 index 000000000..f37db5874 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMS.java @@ -0,0 +1,227 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.Instant; + +/** RecipientDeliveryReportMMS */ +@JsonDeserialize(builder = RecipientDeliveryReportMMSImpl.Builder.class) +public interface RecipientDeliveryReportMMS extends RecipientDeliveryReport { + + /** + * The default originator used for the recipient this delivery report belongs to, if default + * originator pool configured and no originator set when submitting batch. + * + * @return appliedOriginator + */ + String getAppliedOriginator(); + + /** + * A timestamp of when the Delivery Report was created in the Sinch service. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return createdAt + */ + Instant getCreatedAt(); + + /** + * The ID of the batch this delivery report belongs to + * + * @return batchId + * @readOnly This field is returned by the server and cannot be modified + */ + String getBatchId(); + + /** + * The client identifier of the batch this delivery report belongs to, if set when submitting + * batch. + * + * @return clientReference + */ + String getClientReference(); + + /** + * The detailed status + * code. + * + * @return code + */ + DeliveryReceiptErrorCode getCode(); + + /** + * Get encoding + * + * @return encoding + */ + EncodingType getEncoding(); + + /** + * The number of parts the message was split into. Present only if + * max_number_of_message_parts parameter was set. + * + * @return numberOfMessageParts + */ + Integer getNumberOfMessageParts(); + + /** + * The operator that was used for delivering the message to this recipient, if enabled on the + * account by Sinch. + * + * @return operator + */ + String getOperator(); + + /** + * A timestamp extracted from the Delivery Receipt from the originating SMSC. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return operatorStatusAt + */ + Instant getOperatorStatusAt(); + + /** + * Phone number that was queried. + * + * @return recipient + */ + String getRecipient(); + + /** + * Get status + * + * @return status + */ + DeliveryStatus getStatus(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new RecipientDeliveryReportMMSImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param appliedOriginator see getter + * @return Current builder + * @see #getAppliedOriginator + */ + Builder setAppliedOriginator(String appliedOriginator); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param batchId see getter + * @return Current builder + * @see #getBatchId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setBatchId(String batchId); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param code see getter + * @return Current builder + * @see #getCode + */ + Builder setCode(DeliveryReceiptErrorCode code); + + /** + * see getter + * + * @param encoding see getter + * @return Current builder + * @see #getEncoding + */ + Builder setEncoding(EncodingType encoding); + + /** + * see getter + * + * @param numberOfMessageParts see getter + * @return Current builder + * @see #getNumberOfMessageParts + */ + Builder setNumberOfMessageParts(Integer numberOfMessageParts); + + /** + * see getter + * + * @param operator see getter + * @return Current builder + * @see #getOperator + */ + Builder setOperator(String operator); + + /** + * see getter + * + * @param operatorStatusAt see getter + * @return Current builder + * @see #getOperatorStatusAt + */ + Builder setOperatorStatusAt(Instant operatorStatusAt); + + /** + * see getter + * + * @param recipient see getter + * @return Current builder + * @see #getRecipient + */ + Builder setRecipient(String recipient); + + /** + * see getter + * + * @param status see getter + * @return Current builder + * @see #getStatus + */ + Builder setStatus(DeliveryStatus status); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + RecipientDeliveryReportMMS build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMSImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMSImpl.java new file mode 100644 index 000000000..78827fc05 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportMMSImpl.java @@ -0,0 +1,441 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.time.Instant; +import java.util.Arrays; +import java.util.Objects; +import java.util.stream.Stream; + +@JsonPropertyOrder({ + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_APPLIED_ORIGINATOR, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_AT, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_BATCH_ID, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_CLIENT_REFERENCE, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_CODE, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_ENCODING, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_OPERATOR, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_OPERATOR_STATUS_AT, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_RECIPIENT, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_STATUS, + RecipientDeliveryReportMMSImpl.JSON_PROPERTY_TYPE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class RecipientDeliveryReportMMSImpl + implements RecipientDeliveryReportMMS, RecipientDeliveryReport { + private static final long serialVersionUID = 1L; + + /** Gets or Sets type */ + public static class TypeEnum extends EnumDynamic { + public static final TypeEnum RECIPIENT_DELIVERY_REPORT_MMS = + new TypeEnum("recipient_delivery_report_mms"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + TypeEnum.class, TypeEnum::new, Arrays.asList(RECIPIENT_DELIVERY_REPORT_MMS)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + public static final String JSON_PROPERTY_APPLIED_ORIGINATOR = "applied_originator"; + + private OptionalValue appliedOriginator; + + public static final String JSON_PROPERTY_AT = "at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_BATCH_ID = "batch_id"; + + private OptionalValue batchId; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_CODE = "code"; + + private OptionalValue code; + + public static final String JSON_PROPERTY_ENCODING = "encoding"; + + private OptionalValue encoding; + + public static final String JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS = "number_of_message_parts"; + + private OptionalValue numberOfMessageParts; + + public static final String JSON_PROPERTY_OPERATOR = "operator"; + + private OptionalValue operator; + + public static final String JSON_PROPERTY_OPERATOR_STATUS_AT = "operator_status_at"; + + private OptionalValue operatorStatusAt; + + public static final String JSON_PROPERTY_RECIPIENT = "recipient"; + + private OptionalValue recipient; + + public static final String JSON_PROPERTY_STATUS = "status"; + + private OptionalValue status; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public RecipientDeliveryReportMMSImpl() {} + + protected RecipientDeliveryReportMMSImpl( + OptionalValue appliedOriginator, + OptionalValue createdAt, + OptionalValue batchId, + OptionalValue clientReference, + OptionalValue code, + OptionalValue encoding, + OptionalValue numberOfMessageParts, + OptionalValue operator, + OptionalValue operatorStatusAt, + OptionalValue recipient, + OptionalValue status, + OptionalValue type) { + this.appliedOriginator = appliedOriginator; + this.createdAt = createdAt; + this.batchId = batchId; + this.clientReference = clientReference; + this.code = code; + this.encoding = encoding; + this.numberOfMessageParts = numberOfMessageParts; + this.operator = operator; + this.operatorStatusAt = operatorStatusAt; + this.recipient = recipient; + this.status = status; + this.type = type; + } + + @JsonIgnore + public String getAppliedOriginator() { + return appliedOriginator.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_APPLIED_ORIGINATOR) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue appliedOriginator() { + return appliedOriginator; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_AT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public String getBatchId() { + return batchId.orElse(null); + } + + @JsonIgnore + public OptionalValue batchId() { + return batchId; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public DeliveryReceiptErrorCode getCode() { + return code.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue code() { + return code; + } + + @JsonIgnore + public EncodingType getEncoding() { + return encoding.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ENCODING) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue encoding() { + return encoding; + } + + @JsonIgnore + public Integer getNumberOfMessageParts() { + return numberOfMessageParts.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue numberOfMessageParts() { + return numberOfMessageParts; + } + + @JsonIgnore + public String getOperator() { + return operator.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operator() { + return operator; + } + + @JsonIgnore + public Instant getOperatorStatusAt() { + return operatorStatusAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_STATUS_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operatorStatusAt() { + return operatorStatusAt; + } + + @JsonIgnore + public String getRecipient() { + return recipient.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECIPIENT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue recipient() { + return recipient; + } + + @JsonIgnore + public DeliveryStatus getStatus() { + return status.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STATUS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue status() { + return status; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + /** Return true if this RecipientDeliveryReportMMS object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RecipientDeliveryReportMMSImpl recipientDeliveryReportMMS = (RecipientDeliveryReportMMSImpl) o; + return Objects.equals(this.appliedOriginator, recipientDeliveryReportMMS.appliedOriginator) + && Objects.equals(this.createdAt, recipientDeliveryReportMMS.createdAt) + && Objects.equals(this.batchId, recipientDeliveryReportMMS.batchId) + && Objects.equals(this.clientReference, recipientDeliveryReportMMS.clientReference) + && Objects.equals(this.code, recipientDeliveryReportMMS.code) + && Objects.equals(this.encoding, recipientDeliveryReportMMS.encoding) + && Objects.equals( + this.numberOfMessageParts, recipientDeliveryReportMMS.numberOfMessageParts) + && Objects.equals(this.operator, recipientDeliveryReportMMS.operator) + && Objects.equals(this.operatorStatusAt, recipientDeliveryReportMMS.operatorStatusAt) + && Objects.equals(this.recipient, recipientDeliveryReportMMS.recipient) + && Objects.equals(this.status, recipientDeliveryReportMMS.status) + && Objects.equals(this.type, recipientDeliveryReportMMS.type); + } + + @Override + public int hashCode() { + return Objects.hash( + appliedOriginator, + createdAt, + batchId, + clientReference, + code, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt, + recipient, + status, + type); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class RecipientDeliveryReportMMSImpl {\n"); + sb.append(" appliedOriginator: ").append(toIndentedString(appliedOriginator)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" batchId: ").append(toIndentedString(batchId)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" encoding: ").append(toIndentedString(encoding)).append("\n"); + sb.append(" numberOfMessageParts: ") + .append(toIndentedString(numberOfMessageParts)) + .append("\n"); + sb.append(" operator: ").append(toIndentedString(operator)).append("\n"); + sb.append(" operatorStatusAt: ").append(toIndentedString(operatorStatusAt)).append("\n"); + sb.append(" recipient: ").append(toIndentedString(recipient)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements RecipientDeliveryReportMMS.Builder { + OptionalValue appliedOriginator = OptionalValue.empty(); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue batchId = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue code = OptionalValue.empty(); + OptionalValue encoding = OptionalValue.empty(); + OptionalValue numberOfMessageParts = OptionalValue.empty(); + OptionalValue operator = OptionalValue.empty(); + OptionalValue operatorStatusAt = OptionalValue.empty(); + OptionalValue recipient = OptionalValue.empty(); + OptionalValue status = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.RECIPIENT_DELIVERY_REPORT_MMS); + + @JsonProperty(JSON_PROPERTY_APPLIED_ORIGINATOR) + public Builder setAppliedOriginator(String appliedOriginator) { + this.appliedOriginator = OptionalValue.of(appliedOriginator); + return this; + } + + @JsonProperty(JSON_PROPERTY_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_BATCH_ID) + public Builder setBatchId(String batchId) { + this.batchId = OptionalValue.of(batchId); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_CODE) + public Builder setCode(DeliveryReceiptErrorCode code) { + this.code = OptionalValue.of(code); + return this; + } + + @JsonProperty(JSON_PROPERTY_ENCODING) + public Builder setEncoding(EncodingType encoding) { + this.encoding = OptionalValue.of(encoding); + return this; + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS) + public Builder setNumberOfMessageParts(Integer numberOfMessageParts) { + this.numberOfMessageParts = OptionalValue.of(numberOfMessageParts); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR) + public Builder setOperator(String operator) { + this.operator = OptionalValue.of(operator); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_STATUS_AT) + public Builder setOperatorStatusAt(Instant operatorStatusAt) { + this.operatorStatusAt = OptionalValue.of(operatorStatusAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_RECIPIENT) + public Builder setRecipient(String recipient) { + this.recipient = OptionalValue.of(recipient); + return this; + } + + @JsonProperty(JSON_PROPERTY_STATUS) + public Builder setStatus(DeliveryStatus status) { + this.status = OptionalValue.of(status); + return this; + } + + public RecipientDeliveryReportMMS build() { + return new RecipientDeliveryReportMMSImpl( + appliedOriginator, + createdAt, + batchId, + clientReference, + code, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt, + recipient, + status, + type); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMS.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMS.java new file mode 100644 index 000000000..0e1bd17ad --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMS.java @@ -0,0 +1,227 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.Instant; + +/** RecipientDeliveryReportSMS */ +@JsonDeserialize(builder = RecipientDeliveryReportSMSImpl.Builder.class) +public interface RecipientDeliveryReportSMS extends RecipientDeliveryReport { + + /** + * The default originator used for the recipient this delivery report belongs to, if default + * originator pool configured and no originator set when submitting batch. + * + * @return appliedOriginator + */ + String getAppliedOriginator(); + + /** + * A timestamp of when the Delivery Report was created in the Sinch service. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return createdAt + */ + Instant getCreatedAt(); + + /** + * The ID of the batch this delivery report belongs to + * + * @return batchId + * @readOnly This field is returned by the server and cannot be modified + */ + String getBatchId(); + + /** + * The client identifier of the batch this delivery report belongs to, if set when submitting + * batch. + * + * @return clientReference + */ + String getClientReference(); + + /** + * The detailed status + * code. + * + * @return code + */ + DeliveryReceiptErrorCode getCode(); + + /** + * Get encoding + * + * @return encoding + */ + EncodingType getEncoding(); + + /** + * The number of parts the message was split into. Present only if + * max_number_of_message_parts parameter was set. + * + * @return numberOfMessageParts + */ + Integer getNumberOfMessageParts(); + + /** + * The operator that was used for delivering the message to this recipient, if enabled on the + * account by Sinch. + * + * @return operator + */ + String getOperator(); + + /** + * A timestamp extracted from the Delivery Receipt from the originating SMSC. Formatted as ISO-8601: YYYY-MM-DDThh:mm:ss.SSSZ + * . + * + * @return operatorStatusAt + */ + Instant getOperatorStatusAt(); + + /** + * Phone number that was queried. + * + * @return recipient + */ + String getRecipient(); + + /** + * Get status + * + * @return status + */ + DeliveryStatus getStatus(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new RecipientDeliveryReportSMSImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param appliedOriginator see getter + * @return Current builder + * @see #getAppliedOriginator + */ + Builder setAppliedOriginator(String appliedOriginator); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param batchId see getter + * @return Current builder + * @see #getBatchId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setBatchId(String batchId); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * see getter + * + * @param code see getter + * @return Current builder + * @see #getCode + */ + Builder setCode(DeliveryReceiptErrorCode code); + + /** + * see getter + * + * @param encoding see getter + * @return Current builder + * @see #getEncoding + */ + Builder setEncoding(EncodingType encoding); + + /** + * see getter + * + * @param numberOfMessageParts see getter + * @return Current builder + * @see #getNumberOfMessageParts + */ + Builder setNumberOfMessageParts(Integer numberOfMessageParts); + + /** + * see getter + * + * @param operator see getter + * @return Current builder + * @see #getOperator + */ + Builder setOperator(String operator); + + /** + * see getter + * + * @param operatorStatusAt see getter + * @return Current builder + * @see #getOperatorStatusAt + */ + Builder setOperatorStatusAt(Instant operatorStatusAt); + + /** + * see getter + * + * @param recipient see getter + * @return Current builder + * @see #getRecipient + */ + Builder setRecipient(String recipient); + + /** + * see getter + * + * @param status see getter + * @return Current builder + * @see #getStatus + */ + Builder setStatus(DeliveryStatus status); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + RecipientDeliveryReportSMS build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMSImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMSImpl.java new file mode 100644 index 000000000..9101ab9d7 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportSMSImpl.java @@ -0,0 +1,441 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.time.Instant; +import java.util.Arrays; +import java.util.Objects; +import java.util.stream.Stream; + +@JsonPropertyOrder({ + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_APPLIED_ORIGINATOR, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_AT, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_BATCH_ID, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_CLIENT_REFERENCE, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_CODE, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_ENCODING, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_OPERATOR, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_OPERATOR_STATUS_AT, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_RECIPIENT, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_STATUS, + RecipientDeliveryReportSMSImpl.JSON_PROPERTY_TYPE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class RecipientDeliveryReportSMSImpl + implements RecipientDeliveryReportSMS, RecipientDeliveryReport { + private static final long serialVersionUID = 1L; + + /** Gets or Sets type */ + public static class TypeEnum extends EnumDynamic { + public static final TypeEnum RECIPIENT_DELIVERY_REPORT_SMS = + new TypeEnum("recipient_delivery_report_sms"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + TypeEnum.class, TypeEnum::new, Arrays.asList(RECIPIENT_DELIVERY_REPORT_SMS)); + + private TypeEnum(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TypeEnum from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TypeEnum e) { + return ENUM_SUPPORT.valueOf(e); + } + } + + public static final String JSON_PROPERTY_APPLIED_ORIGINATOR = "applied_originator"; + + private OptionalValue appliedOriginator; + + public static final String JSON_PROPERTY_AT = "at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_BATCH_ID = "batch_id"; + + private OptionalValue batchId; + + public static final String JSON_PROPERTY_CLIENT_REFERENCE = "client_reference"; + + private OptionalValue clientReference; + + public static final String JSON_PROPERTY_CODE = "code"; + + private OptionalValue code; + + public static final String JSON_PROPERTY_ENCODING = "encoding"; + + private OptionalValue encoding; + + public static final String JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS = "number_of_message_parts"; + + private OptionalValue numberOfMessageParts; + + public static final String JSON_PROPERTY_OPERATOR = "operator"; + + private OptionalValue operator; + + public static final String JSON_PROPERTY_OPERATOR_STATUS_AT = "operator_status_at"; + + private OptionalValue operatorStatusAt; + + public static final String JSON_PROPERTY_RECIPIENT = "recipient"; + + private OptionalValue recipient; + + public static final String JSON_PROPERTY_STATUS = "status"; + + private OptionalValue status; + + public static final String JSON_PROPERTY_TYPE = "type"; + + private OptionalValue type; + + public RecipientDeliveryReportSMSImpl() {} + + protected RecipientDeliveryReportSMSImpl( + OptionalValue appliedOriginator, + OptionalValue createdAt, + OptionalValue batchId, + OptionalValue clientReference, + OptionalValue code, + OptionalValue encoding, + OptionalValue numberOfMessageParts, + OptionalValue operator, + OptionalValue operatorStatusAt, + OptionalValue recipient, + OptionalValue status, + OptionalValue type) { + this.appliedOriginator = appliedOriginator; + this.createdAt = createdAt; + this.batchId = batchId; + this.clientReference = clientReference; + this.code = code; + this.encoding = encoding; + this.numberOfMessageParts = numberOfMessageParts; + this.operator = operator; + this.operatorStatusAt = operatorStatusAt; + this.recipient = recipient; + this.status = status; + this.type = type; + } + + @JsonIgnore + public String getAppliedOriginator() { + return appliedOriginator.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_APPLIED_ORIGINATOR) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue appliedOriginator() { + return appliedOriginator; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_AT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public String getBatchId() { + return batchId.orElse(null); + } + + @JsonIgnore + public OptionalValue batchId() { + return batchId; + } + + @JsonIgnore + public String getClientReference() { + return clientReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue clientReference() { + return clientReference; + } + + @JsonIgnore + public DeliveryReceiptErrorCode getCode() { + return code.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue code() { + return code; + } + + @JsonIgnore + public EncodingType getEncoding() { + return encoding.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ENCODING) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue encoding() { + return encoding; + } + + @JsonIgnore + public Integer getNumberOfMessageParts() { + return numberOfMessageParts.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue numberOfMessageParts() { + return numberOfMessageParts; + } + + @JsonIgnore + public String getOperator() { + return operator.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operator() { + return operator; + } + + @JsonIgnore + public Instant getOperatorStatusAt() { + return operatorStatusAt.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_STATUS_AT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue operatorStatusAt() { + return operatorStatusAt; + } + + @JsonIgnore + public String getRecipient() { + return recipient.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_RECIPIENT) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue recipient() { + return recipient; + } + + @JsonIgnore + public DeliveryStatus getStatus() { + return status.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_STATUS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue status() { + return status; + } + + @JsonIgnore + public TypeEnum getType() { + return type.orElse(null); + } + + @JsonIgnore + public OptionalValue type() { + return type; + } + + /** Return true if this RecipientDeliveryReportSMS object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RecipientDeliveryReportSMSImpl recipientDeliveryReportSMS = (RecipientDeliveryReportSMSImpl) o; + return Objects.equals(this.appliedOriginator, recipientDeliveryReportSMS.appliedOriginator) + && Objects.equals(this.createdAt, recipientDeliveryReportSMS.createdAt) + && Objects.equals(this.batchId, recipientDeliveryReportSMS.batchId) + && Objects.equals(this.clientReference, recipientDeliveryReportSMS.clientReference) + && Objects.equals(this.code, recipientDeliveryReportSMS.code) + && Objects.equals(this.encoding, recipientDeliveryReportSMS.encoding) + && Objects.equals( + this.numberOfMessageParts, recipientDeliveryReportSMS.numberOfMessageParts) + && Objects.equals(this.operator, recipientDeliveryReportSMS.operator) + && Objects.equals(this.operatorStatusAt, recipientDeliveryReportSMS.operatorStatusAt) + && Objects.equals(this.recipient, recipientDeliveryReportSMS.recipient) + && Objects.equals(this.status, recipientDeliveryReportSMS.status) + && Objects.equals(this.type, recipientDeliveryReportSMS.type); + } + + @Override + public int hashCode() { + return Objects.hash( + appliedOriginator, + createdAt, + batchId, + clientReference, + code, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt, + recipient, + status, + type); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class RecipientDeliveryReportSMSImpl {\n"); + sb.append(" appliedOriginator: ").append(toIndentedString(appliedOriginator)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" batchId: ").append(toIndentedString(batchId)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" encoding: ").append(toIndentedString(encoding)).append("\n"); + sb.append(" numberOfMessageParts: ") + .append(toIndentedString(numberOfMessageParts)) + .append("\n"); + sb.append(" operator: ").append(toIndentedString(operator)).append("\n"); + sb.append(" operatorStatusAt: ").append(toIndentedString(operatorStatusAt)).append("\n"); + sb.append(" recipient: ").append(toIndentedString(recipient)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements RecipientDeliveryReportSMS.Builder { + OptionalValue appliedOriginator = OptionalValue.empty(); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue batchId = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + OptionalValue code = OptionalValue.empty(); + OptionalValue encoding = OptionalValue.empty(); + OptionalValue numberOfMessageParts = OptionalValue.empty(); + OptionalValue operator = OptionalValue.empty(); + OptionalValue operatorStatusAt = OptionalValue.empty(); + OptionalValue recipient = OptionalValue.empty(); + OptionalValue status = OptionalValue.empty(); + OptionalValue type = OptionalValue.of(TypeEnum.RECIPIENT_DELIVERY_REPORT_SMS); + + @JsonProperty(JSON_PROPERTY_APPLIED_ORIGINATOR) + public Builder setAppliedOriginator(String appliedOriginator) { + this.appliedOriginator = OptionalValue.of(appliedOriginator); + return this; + } + + @JsonProperty(JSON_PROPERTY_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_BATCH_ID) + public Builder setBatchId(String batchId) { + this.batchId = OptionalValue.of(batchId); + return this; + } + + @JsonProperty(JSON_PROPERTY_CLIENT_REFERENCE) + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_CODE) + public Builder setCode(DeliveryReceiptErrorCode code) { + this.code = OptionalValue.of(code); + return this; + } + + @JsonProperty(JSON_PROPERTY_ENCODING) + public Builder setEncoding(EncodingType encoding) { + this.encoding = OptionalValue.of(encoding); + return this; + } + + @JsonProperty(JSON_PROPERTY_NUMBER_OF_MESSAGE_PARTS) + public Builder setNumberOfMessageParts(Integer numberOfMessageParts) { + this.numberOfMessageParts = OptionalValue.of(numberOfMessageParts); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR) + public Builder setOperator(String operator) { + this.operator = OptionalValue.of(operator); + return this; + } + + @JsonProperty(JSON_PROPERTY_OPERATOR_STATUS_AT) + public Builder setOperatorStatusAt(Instant operatorStatusAt) { + this.operatorStatusAt = OptionalValue.of(operatorStatusAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_RECIPIENT) + public Builder setRecipient(String recipient) { + this.recipient = OptionalValue.of(recipient); + return this; + } + + @JsonProperty(JSON_PROPERTY_STATUS) + public Builder setStatus(DeliveryStatus status) { + this.status = OptionalValue.of(status); + return this; + } + + public RecipientDeliveryReportSMS build() { + return new RecipientDeliveryReportSMSImpl( + appliedOriginator, + createdAt, + batchId, + clientReference, + code, + encoding, + numberOfMessageParts, + operator, + operatorStatusAt, + recipient, + status, + type); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOf.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOf.java new file mode 100644 index 000000000..026a9d49a --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOf.java @@ -0,0 +1,17 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize( + using = BatchDeliveryReportOneOfImpl.BatchDeliveryReportOneOfImplDeserializer.class) +public interface BatchDeliveryReportOneOf {} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOfImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOfImpl.java new file mode 100644 index 000000000..2783481a5 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/BatchDeliveryReportOneOfImpl.java @@ -0,0 +1,337 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.utils.databind.JSONNavigator; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportMMSImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportSMSImpl; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +@JsonDeserialize( + using = BatchDeliveryReportOneOfImpl.BatchDeliveryReportOneOfImplDeserializer.class) +@JsonSerialize(using = BatchDeliveryReportOneOfImpl.BatchDeliveryReportOneOfImplSerializer.class) +public class BatchDeliveryReportOneOfImpl extends AbstractOpenApiSchema + implements BatchDeliveryReportOneOf { + private static final Logger log = Logger.getLogger(BatchDeliveryReportOneOfImpl.class.getName()); + + public static final class BatchDeliveryReportOneOfImplSerializer + extends StdSerializer { + private static final long serialVersionUID = 1L; + + public BatchDeliveryReportOneOfImplSerializer(Class t) { + super(t); + } + + public BatchDeliveryReportOneOfImplSerializer() { + this(null); + } + + @Override + public void serialize( + BatchDeliveryReportOneOfImpl value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.getActualInstance()); + } + } + + public static final class BatchDeliveryReportOneOfImplDeserializer + extends StdDeserializer { + + private static final long serialVersionUID = 1L; + + public BatchDeliveryReportOneOfImplDeserializer() { + this(BatchDeliveryReportOneOfImpl.class); + } + + public BatchDeliveryReportOneOfImplDeserializer(Class vc) { + super(vc); + } + + @Override + public BatchDeliveryReportOneOfImpl deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode tree = jp.readValueAsTree(); + Object deserialized = null; + BatchDeliveryReportOneOfImpl newBatchDeliveryReportOneOfImpl = + new BatchDeliveryReportOneOfImpl(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "delivery_report_mms": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportMMSImpl.class); + newBatchDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newBatchDeliveryReportOneOfImpl; + case "delivery_report_sms": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportSMSImpl.class); + newBatchDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newBatchDeliveryReportOneOfImpl; + case "BatchDeliveryReportMMS": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportMMSImpl.class); + newBatchDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newBatchDeliveryReportOneOfImpl; + case "BatchDeliveryReportSMS": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportSMSImpl.class); + newBatchDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newBatchDeliveryReportOneOfImpl; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for BatchDeliveryReportOneOfImpl." + + " Possible values: delivery_report_mms delivery_report_sms" + + " BatchDeliveryReportMMS BatchDeliveryReportSMS", + discriminatorValue)); + } + + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize BatchDeliveryReportMMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchDeliveryReportMMSImpl.class.equals(Integer.class) + || BatchDeliveryReportMMSImpl.class.equals(Long.class) + || BatchDeliveryReportMMSImpl.class.equals(Float.class) + || BatchDeliveryReportMMSImpl.class.equals(Double.class) + || BatchDeliveryReportMMSImpl.class.equals(Boolean.class) + || BatchDeliveryReportMMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchDeliveryReportMMSImpl.class.equals(Integer.class) + || BatchDeliveryReportMMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchDeliveryReportMMSImpl.class.equals(Float.class) + || BatchDeliveryReportMMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchDeliveryReportMMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchDeliveryReportMMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportMMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchDeliveryReportMMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchDeliveryReportMMSImpl'", e); + } + + // deserialize BatchDeliveryReportSMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchDeliveryReportSMSImpl.class.equals(Integer.class) + || BatchDeliveryReportSMSImpl.class.equals(Long.class) + || BatchDeliveryReportSMSImpl.class.equals(Float.class) + || BatchDeliveryReportSMSImpl.class.equals(Double.class) + || BatchDeliveryReportSMSImpl.class.equals(Boolean.class) + || BatchDeliveryReportSMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchDeliveryReportSMSImpl.class.equals(Integer.class) + || BatchDeliveryReportSMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchDeliveryReportSMSImpl.class.equals(Float.class) + || BatchDeliveryReportSMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchDeliveryReportSMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchDeliveryReportSMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportSMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchDeliveryReportSMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchDeliveryReportSMSImpl'", e); + } + + if (match == 1) { + BatchDeliveryReportOneOfImpl ret = new BatchDeliveryReportOneOfImpl(); + ret.setActualInstance(deserialized); + return ret; + } + throw new IOException( + String.format( + "Failed deserialization for BatchDeliveryReportOneOfImpl: %d classes match result," + + " expected 1", + match)); + } + + /** Handle deserialization of the 'null' value. */ + @Override + public BatchDeliveryReportOneOfImpl getNullValue(DeserializationContext ctxt) + throws JsonMappingException { + throw new JsonMappingException( + ctxt.getParser(), "BatchDeliveryReportOneOfImpl cannot be null"); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap<>(); + + public BatchDeliveryReportOneOfImpl() { + super("oneOf", Boolean.FALSE); + } + + public BatchDeliveryReportOneOfImpl(BatchDeliveryReportMMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public BatchDeliveryReportOneOfImpl(BatchDeliveryReportSMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("BatchDeliveryReportMMSImpl", BatchDeliveryReportMMSImpl.class); + schemas.put("BatchDeliveryReportSMSImpl", BatchDeliveryReportSMSImpl.class); + JSONNavigator.registerDescendants( + BatchDeliveryReportOneOfImpl.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("delivery_report_mms", BatchDeliveryReportMMSImpl.class); + mappings.put("delivery_report_sms", BatchDeliveryReportSMSImpl.class); + mappings.put("BatchDeliveryReportMMS", BatchDeliveryReportMMSImpl.class); + mappings.put("BatchDeliveryReportSMS", BatchDeliveryReportSMSImpl.class); + mappings.put("BatchDeliveryReportOneOf", BatchDeliveryReportOneOfImpl.class); + JSONNavigator.registerDiscriminator(BatchDeliveryReportOneOfImpl.class, "type", mappings); + } + + @Override + public Map> getSchemas() { + return BatchDeliveryReportOneOfImpl.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check the instance parameter is valid + * against the oneOf child schemas: BatchDeliveryReportMMSImpl, BatchDeliveryReportSMSImpl + * + *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a + * composed schema (allOf, anyOf, oneOf). + */ + @Override + public void setActualInstance(Object instance) { + if (JSONNavigator.isInstanceOf( + BatchDeliveryReportMMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf( + BatchDeliveryReportSMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException( + "Invalid instance type. Must be BatchDeliveryReportMMSImpl, BatchDeliveryReportSMSImpl"); + } + + /** + * Get the actual instance, which can be the following: BatchDeliveryReportMMSImpl, + * BatchDeliveryReportSMSImpl + * + * @return The actual instance (BatchDeliveryReportMMSImpl, BatchDeliveryReportSMSImpl) + */ + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchDeliveryReportMMSImpl`. If the actual instance is not + * `BatchDeliveryReportMMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `BatchDeliveryReportMMSImpl` + * @throws ClassCastException if the instance is not `BatchDeliveryReportMMSImpl` + */ + public BatchDeliveryReportMMSImpl getBatchDeliveryReportMMSImpl() throws ClassCastException { + return (BatchDeliveryReportMMSImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchDeliveryReportSMSImpl`. If the actual instance is not + * `BatchDeliveryReportSMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `BatchDeliveryReportSMSImpl` + * @throws ClassCastException if the instance is not `BatchDeliveryReportSMSImpl` + */ + public BatchDeliveryReportSMSImpl getBatchDeliveryReportSMSImpl() throws ClassCastException { + return (BatchDeliveryReportSMSImpl) super.getActualInstance(); + } + + public static class Deserializer + extends StdDeserializer< + com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport> { + + public Deserializer() { + this(null); + } + + public Deserializer( + Class vc) { + super(vc); + } + + @Override + public com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport deserialize( + JsonParser jp, DeserializationContext ctxt) throws IOException { + + Object deserialized = jp.readValueAs(BatchDeliveryReportOneOfImpl.class).getActualInstance(); + if (null == deserialized) { + return null; + } + if (!(deserialized + instanceof com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport)) { + log.log(Level.SEVERE, "Input data does not match schema ", deserialized); + return null; + } + + return (com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport) deserialized; + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOf.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOf.java new file mode 100644 index 000000000..930cc0439 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOf.java @@ -0,0 +1,17 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize( + using = RecipientDeliveryReportOneOfImpl.RecipientDeliveryReportOneOfImplDeserializer.class) +public interface RecipientDeliveryReportOneOf {} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOfImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOfImpl.java new file mode 100644 index 000000000..0f0d10b3b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/internal/RecipientDeliveryReportOneOfImpl.java @@ -0,0 +1,353 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.utils.databind.JSONNavigator; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportMMSImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportSMSImpl; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +@JsonDeserialize( + using = RecipientDeliveryReportOneOfImpl.RecipientDeliveryReportOneOfImplDeserializer.class) +@JsonSerialize( + using = RecipientDeliveryReportOneOfImpl.RecipientDeliveryReportOneOfImplSerializer.class) +public class RecipientDeliveryReportOneOfImpl extends AbstractOpenApiSchema + implements RecipientDeliveryReportOneOf { + private static final Logger log = + Logger.getLogger(RecipientDeliveryReportOneOfImpl.class.getName()); + + public static final class RecipientDeliveryReportOneOfImplSerializer + extends StdSerializer { + private static final long serialVersionUID = 1L; + + public RecipientDeliveryReportOneOfImplSerializer(Class t) { + super(t); + } + + public RecipientDeliveryReportOneOfImplSerializer() { + this(null); + } + + @Override + public void serialize( + RecipientDeliveryReportOneOfImpl value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.getActualInstance()); + } + } + + public static final class RecipientDeliveryReportOneOfImplDeserializer + extends StdDeserializer { + + private static final long serialVersionUID = 1L; + + public RecipientDeliveryReportOneOfImplDeserializer() { + this(RecipientDeliveryReportOneOfImpl.class); + } + + public RecipientDeliveryReportOneOfImplDeserializer(Class vc) { + super(vc); + } + + @Override + public RecipientDeliveryReportOneOfImpl deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode tree = jp.readValueAsTree(); + Object deserialized = null; + RecipientDeliveryReportOneOfImpl newRecipientDeliveryReportOneOfImpl = + new RecipientDeliveryReportOneOfImpl(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "recipient_delivery_report_mms": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportMMSImpl.class); + newRecipientDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newRecipientDeliveryReportOneOfImpl; + case "recipient_delivery_report_sms": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportSMSImpl.class); + newRecipientDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newRecipientDeliveryReportOneOfImpl; + case "RecipientDeliveryReportMMS": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportMMSImpl.class); + newRecipientDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newRecipientDeliveryReportOneOfImpl; + case "RecipientDeliveryReportSMS": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportSMSImpl.class); + newRecipientDeliveryReportOneOfImpl.setActualInstance(deserialized); + return newRecipientDeliveryReportOneOfImpl; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for RecipientDeliveryReportOneOfImpl." + + " Possible values: recipient_delivery_report_mms" + + " recipient_delivery_report_sms RecipientDeliveryReportMMS" + + " RecipientDeliveryReportSMS", + discriminatorValue)); + } + + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize RecipientDeliveryReportMMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (RecipientDeliveryReportMMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportMMSImpl.class.equals(Long.class) + || RecipientDeliveryReportMMSImpl.class.equals(Float.class) + || RecipientDeliveryReportMMSImpl.class.equals(Double.class) + || RecipientDeliveryReportMMSImpl.class.equals(Boolean.class) + || RecipientDeliveryReportMMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((RecipientDeliveryReportMMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportMMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((RecipientDeliveryReportMMSImpl.class.equals(Float.class) + || RecipientDeliveryReportMMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (RecipientDeliveryReportMMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (RecipientDeliveryReportMMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportMMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'RecipientDeliveryReportMMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log( + Level.FINER, "Input data does not match schema 'RecipientDeliveryReportMMSImpl'", e); + } + + // deserialize RecipientDeliveryReportSMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (RecipientDeliveryReportSMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportSMSImpl.class.equals(Long.class) + || RecipientDeliveryReportSMSImpl.class.equals(Float.class) + || RecipientDeliveryReportSMSImpl.class.equals(Double.class) + || RecipientDeliveryReportSMSImpl.class.equals(Boolean.class) + || RecipientDeliveryReportSMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((RecipientDeliveryReportSMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportSMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((RecipientDeliveryReportSMSImpl.class.equals(Float.class) + || RecipientDeliveryReportSMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (RecipientDeliveryReportSMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (RecipientDeliveryReportSMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportSMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'RecipientDeliveryReportSMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log( + Level.FINER, "Input data does not match schema 'RecipientDeliveryReportSMSImpl'", e); + } + + if (match == 1) { + RecipientDeliveryReportOneOfImpl ret = new RecipientDeliveryReportOneOfImpl(); + ret.setActualInstance(deserialized); + return ret; + } + throw new IOException( + String.format( + "Failed deserialization for RecipientDeliveryReportOneOfImpl: %d classes match" + + " result, expected 1", + match)); + } + + /** Handle deserialization of the 'null' value. */ + @Override + public RecipientDeliveryReportOneOfImpl getNullValue(DeserializationContext ctxt) + throws JsonMappingException { + throw new JsonMappingException( + ctxt.getParser(), "RecipientDeliveryReportOneOfImpl cannot be null"); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap<>(); + + public RecipientDeliveryReportOneOfImpl() { + super("oneOf", Boolean.FALSE); + } + + public RecipientDeliveryReportOneOfImpl(RecipientDeliveryReportMMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public RecipientDeliveryReportOneOfImpl(RecipientDeliveryReportSMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("RecipientDeliveryReportMMSImpl", RecipientDeliveryReportMMSImpl.class); + schemas.put("RecipientDeliveryReportSMSImpl", RecipientDeliveryReportSMSImpl.class); + JSONNavigator.registerDescendants( + RecipientDeliveryReportOneOfImpl.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("recipient_delivery_report_mms", RecipientDeliveryReportMMSImpl.class); + mappings.put("recipient_delivery_report_sms", RecipientDeliveryReportSMSImpl.class); + mappings.put("RecipientDeliveryReportMMS", RecipientDeliveryReportMMSImpl.class); + mappings.put("RecipientDeliveryReportSMS", RecipientDeliveryReportSMSImpl.class); + mappings.put("RecipientDeliveryReportOneOf", RecipientDeliveryReportOneOfImpl.class); + JSONNavigator.registerDiscriminator(RecipientDeliveryReportOneOfImpl.class, "type", mappings); + } + + @Override + public Map> getSchemas() { + return RecipientDeliveryReportOneOfImpl.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check the instance parameter is valid + * against the oneOf child schemas: RecipientDeliveryReportMMSImpl, RecipientDeliveryReportSMSImpl + * + *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a + * composed schema (allOf, anyOf, oneOf). + */ + @Override + public void setActualInstance(Object instance) { + if (JSONNavigator.isInstanceOf( + RecipientDeliveryReportMMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf( + RecipientDeliveryReportSMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException( + "Invalid instance type. Must be RecipientDeliveryReportMMSImpl," + + " RecipientDeliveryReportSMSImpl"); + } + + /** + * Get the actual instance, which can be the following: RecipientDeliveryReportMMSImpl, + * RecipientDeliveryReportSMSImpl + * + * @return The actual instance (RecipientDeliveryReportMMSImpl, RecipientDeliveryReportSMSImpl) + */ + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `RecipientDeliveryReportMMSImpl`. If the actual instance is not + * `RecipientDeliveryReportMMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `RecipientDeliveryReportMMSImpl` + * @throws ClassCastException if the instance is not `RecipientDeliveryReportMMSImpl` + */ + public RecipientDeliveryReportMMSImpl getRecipientDeliveryReportMMSImpl() + throws ClassCastException { + return (RecipientDeliveryReportMMSImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `RecipientDeliveryReportSMSImpl`. If the actual instance is not + * `RecipientDeliveryReportSMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `RecipientDeliveryReportSMSImpl` + * @throws ClassCastException if the instance is not `RecipientDeliveryReportSMSImpl` + */ + public RecipientDeliveryReportSMSImpl getRecipientDeliveryReportSMSImpl() + throws ClassCastException { + return (RecipientDeliveryReportSMSImpl) super.getActualInstance(); + } + + public static class Deserializer + extends StdDeserializer< + com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport> { + + public Deserializer() { + this(null); + } + + public Deserializer( + Class vc) { + super(vc); + } + + @Override + public com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport deserialize( + JsonParser jp, DeserializationContext ctxt) throws IOException { + + Object deserialized = + jp.readValueAs(RecipientDeliveryReportOneOfImpl.class).getActualInstance(); + if (null == deserialized) { + return null; + } + if (!(deserialized + instanceof com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport)) { + log.log(Level.SEVERE, "Input data does not match schema ", deserialized); + return null; + } + + return (com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport) + deserialized; + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParameters.java new file mode 100644 index 000000000..3186733ea --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParameters.java @@ -0,0 +1,97 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.request; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import java.util.List; + +/** BatchDeliveryReportQueryParameters */ +public interface BatchDeliveryReportQueryParameters { + + /** + * Get type + * + * @return type + */ + OptionalValue getType(); + + /** + * Get status + * + * @return status + */ + OptionalValue> getStatus(); + + /** + * Get code + * + * @return code + */ + OptionalValue> getCode(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new BatchDeliveryReportQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(BatchDeliveryReportQueryParameters parameters) { + return new BatchDeliveryReportQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param type see getter + * @return Current builder + * @see #getType + */ + Builder setType(QueryReportType type); + + /** + * see getter + * + * @param status see getter + * @return Current builder + * @see #getStatus + */ + Builder setStatus(List status); + + /** + * see getter + * + * @param code see getter + * @return Current builder + * @see #getCode + */ + Builder setCode(List code); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + BatchDeliveryReportQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParametersImpl.java new file mode 100644 index 000000000..8d7e4c835 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/BatchDeliveryReportQueryParametersImpl.java @@ -0,0 +1,115 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.request; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import java.util.List; +import java.util.Objects; + +public class BatchDeliveryReportQueryParametersImpl implements BatchDeliveryReportQueryParameters { + + private final OptionalValue type; + private final OptionalValue> status; + private final OptionalValue> code; + + private BatchDeliveryReportQueryParametersImpl( + OptionalValue type, + OptionalValue> status, + OptionalValue> code) { + this.type = type; + this.status = status; + this.code = code; + } + + public OptionalValue getType() { + return type; + } + + public OptionalValue> getStatus() { + return status; + } + + public OptionalValue> getCode() { + return code; + } + + /** Return true if this GetDeliveryReportByBatchIdQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BatchDeliveryReportQueryParametersImpl getDeliveryReportByBatchIdQueryParameters = + (BatchDeliveryReportQueryParametersImpl) o; + return Objects.equals(this.type, getDeliveryReportByBatchIdQueryParameters.type) + && Objects.equals(this.status, getDeliveryReportByBatchIdQueryParameters.status) + && Objects.equals(this.code, getDeliveryReportByBatchIdQueryParameters.code); + } + + @Override + public int hashCode() { + return Objects.hash(type, status, code); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class BatchDeliveryReportQueryParametersImpl {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).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 "); + } + + static class Builder implements BatchDeliveryReportQueryParameters.Builder { + OptionalValue type = OptionalValue.empty(); + OptionalValue> status = OptionalValue.empty(); + OptionalValue> code = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(BatchDeliveryReportQueryParameters _parameters) { + if (null == _parameters) { + return; + } + BatchDeliveryReportQueryParametersImpl parameters = + (BatchDeliveryReportQueryParametersImpl) _parameters; + this.type = parameters.getType(); + this.status = parameters.getStatus(); + this.code = parameters.getCode(); + } + + public Builder setType(QueryReportType type) { + this.type = OptionalValue.of(type); + return this; + } + + public Builder setStatus(List status) { + this.status = OptionalValue.of(status); + return this; + } + + public Builder setCode(List code) { + this.code = OptionalValue.of(code); + return this; + } + + public BatchDeliveryReportQueryParameters build() { + return new BatchDeliveryReportQueryParametersImpl(type, status, code); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParameters.java new file mode 100644 index 000000000..2f6f4f144 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParameters.java @@ -0,0 +1,162 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.request; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import java.time.Instant; +import java.util.List; + +/** ListDeliveryReportsQueryParameters */ +public interface ListDeliveryReportsQueryParameters { + + /** + * Get page minimum: 0 + * + * @return page + */ + OptionalValue getPage(); + + /** + * Get pageSize minimum: 1 maximum: 100 + * + * @return pageSize + */ + OptionalValue getPageSize(); + + /** + * Get startDate + * + * @return startDate + */ + OptionalValue getStartDate(); + + /** + * Get endDate + * + * @return endDate + */ + OptionalValue getEndDate(); + + /** + * Get status + * + * @return status + */ + OptionalValue> getStatus(); + + /** + * Get code + * + * @return code + */ + OptionalValue> getCode(); + + /** + * Get clientReference + * + * @return clientReference + */ + OptionalValue getClientReference(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ListDeliveryReportsQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(ListDeliveryReportsQueryParameters parameters) { + return new ListDeliveryReportsQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param startDate see getter + * @return Current builder + * @see #getStartDate + */ + Builder setStartDate(Instant startDate); + + /** + * see getter + * + * @param endDate see getter + * @return Current builder + * @see #getEndDate + */ + Builder setEndDate(Instant endDate); + + /** + * see getter + * + * @param status see getter + * @return Current builder + * @see #getStatus + */ + Builder setStatus(List status); + + /** + * see getter + * + * @param code see getter + * @return Current builder + * @see #getCode + */ + Builder setCode(List code); + + /** + * see getter + * + * @param clientReference see getter + * @return Current builder + * @see #getClientReference + */ + Builder setClientReference(String clientReference); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ListDeliveryReportsQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParametersImpl.java new file mode 100644 index 000000000..26bc6b5fa --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/ListDeliveryReportsQueryParametersImpl.java @@ -0,0 +1,181 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.request; + +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import java.time.Instant; +import java.util.List; +import java.util.Objects; + +public class ListDeliveryReportsQueryParametersImpl implements ListDeliveryReportsQueryParameters { + + private final OptionalValue page; + private final OptionalValue pageSize; + private final OptionalValue startDate; + private final OptionalValue endDate; + private final OptionalValue> status; + private final OptionalValue> code; + private final OptionalValue clientReference; + + private ListDeliveryReportsQueryParametersImpl( + OptionalValue page, + OptionalValue pageSize, + OptionalValue startDate, + OptionalValue endDate, + OptionalValue> status, + OptionalValue> code, + OptionalValue clientReference) { + this.page = page; + this.pageSize = pageSize; + this.startDate = startDate; + this.endDate = endDate; + this.status = status; + this.code = code; + this.clientReference = clientReference; + } + + public OptionalValue getPage() { + return page; + } + + public OptionalValue getPageSize() { + return pageSize; + } + + public OptionalValue getStartDate() { + return startDate; + } + + public OptionalValue getEndDate() { + return endDate; + } + + public OptionalValue> getStatus() { + return status; + } + + public OptionalValue> getCode() { + return code; + } + + public OptionalValue getClientReference() { + return clientReference; + } + + /** Return true if this GetDeliveryReportsQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ListDeliveryReportsQueryParametersImpl getDeliveryReportsQueryParameters = + (ListDeliveryReportsQueryParametersImpl) o; + return Objects.equals(this.page, getDeliveryReportsQueryParameters.page) + && Objects.equals(this.pageSize, getDeliveryReportsQueryParameters.pageSize) + && Objects.equals(this.startDate, getDeliveryReportsQueryParameters.startDate) + && Objects.equals(this.endDate, getDeliveryReportsQueryParameters.endDate) + && Objects.equals(this.status, getDeliveryReportsQueryParameters.status) + && Objects.equals(this.code, getDeliveryReportsQueryParameters.code) + && Objects.equals(this.clientReference, getDeliveryReportsQueryParameters.clientReference); + } + + @Override + public int hashCode() { + return Objects.hash(page, pageSize, startDate, endDate, status, code, clientReference); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ListDeliveryReportsQueryParametersImpl {\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append(" startDate: ").append(toIndentedString(startDate)).append("\n"); + sb.append(" endDate: ").append(toIndentedString(endDate)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" clientReference: ").append(toIndentedString(clientReference)).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 "); + } + + static class Builder implements ListDeliveryReportsQueryParameters.Builder { + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + OptionalValue startDate = OptionalValue.empty(); + OptionalValue endDate = OptionalValue.empty(); + OptionalValue> status = OptionalValue.empty(); + OptionalValue> code = OptionalValue.empty(); + OptionalValue clientReference = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(ListDeliveryReportsQueryParameters _parameters) { + if (null == _parameters) { + return; + } + ListDeliveryReportsQueryParametersImpl parameters = + (ListDeliveryReportsQueryParametersImpl) _parameters; + this.page = parameters.getPage(); + this.pageSize = parameters.getPageSize(); + this.startDate = parameters.getStartDate(); + this.endDate = parameters.getEndDate(); + this.status = parameters.getStatus(); + this.code = parameters.getCode(); + this.clientReference = parameters.getClientReference(); + } + + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public Builder setStartDate(Instant startDate) { + this.startDate = OptionalValue.of(startDate); + return this; + } + + public Builder setEndDate(Instant endDate) { + this.endDate = OptionalValue.of(endDate); + return this; + } + + public Builder setStatus(List status) { + this.status = OptionalValue.of(status); + return this; + } + + public Builder setCode(List code) { + this.code = OptionalValue.of(code); + return this; + } + + public Builder setClientReference(String clientReference) { + this.clientReference = OptionalValue.of(clientReference); + return this; + } + + public ListDeliveryReportsQueryParameters build() { + return new ListDeliveryReportsQueryParametersImpl( + page, pageSize, startDate, endDate, status, code, clientReference); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/QueryReportType.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/QueryReportType.java new file mode 100644 index 000000000..d61251f7a --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/QueryReportType.java @@ -0,0 +1,36 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.request; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Kind of delivery report */ +public class QueryReportType extends EnumDynamic { + + /** Will count the number of messages sent per status. */ + public static final QueryReportType SUMMARY = new QueryReportType("summary"); + + /** Report give that of a summary report but in addition, lists phone numbers. */ + public static final QueryReportType FULL = new QueryReportType("full"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + QueryReportType.class, QueryReportType::new, Arrays.asList(SUMMARY, FULL)); + + private QueryReportType(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static QueryReportType from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(QueryReportType e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java new file mode 100644 index 000000000..9fcb56fe2 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java @@ -0,0 +1,104 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import java.util.List; + +/** DeliveryReportList */ +@JsonDeserialize(builder = DeliveryReportListImpl.Builder.class) +public interface DeliveryReportList { + + /** + * The total number of entries matching the given filters. + * + * @return count + */ + Long getCount(); + + /** + * The requested page. + * + * @return page + */ + Integer getPage(); + + /** + * The number of entries returned in this request. + * + * @return pageSize + */ + Integer getPageSize(); + + /** + * The page of delivery reports matching the given filters. + * + * @return deliveryReports + */ + List getDeliveryReports(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new DeliveryReportListImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param count see getter + * @return Current builder + * @see #getCount + */ + Builder setCount(Long count); + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param deliveryReports see getter + * @return Current builder + * @see #getDeliveryReports + */ + Builder setDeliveryReports(List deliveryReports); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + DeliveryReportList build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java new file mode 100644 index 000000000..d84a1e029 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java @@ -0,0 +1,176 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + DeliveryReportListImpl.JSON_PROPERTY_COUNT, + DeliveryReportListImpl.JSON_PROPERTY_PAGE, + DeliveryReportListImpl.JSON_PROPERTY_PAGE_SIZE, + DeliveryReportListImpl.JSON_PROPERTY_DELIVERY_REPORTS +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class DeliveryReportListImpl implements DeliveryReportList { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_COUNT = "count"; + + private OptionalValue count; + + public static final String JSON_PROPERTY_PAGE = "page"; + + private OptionalValue page; + + public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; + + private OptionalValue pageSize; + + public static final String JSON_PROPERTY_DELIVERY_REPORTS = "delivery_reports"; + + private OptionalValue> deliveryReports; + + public DeliveryReportListImpl() {} + + protected DeliveryReportListImpl( + OptionalValue count, + OptionalValue page, + OptionalValue pageSize, + OptionalValue> deliveryReports) { + this.count = count; + this.page = page; + this.pageSize = pageSize; + this.deliveryReports = deliveryReports; + } + + @JsonIgnore + public Long getCount() { + return count.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue count() { + return count; + } + + @JsonIgnore + public Integer getPage() { + return page.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue page() { + return page; + } + + @JsonIgnore + public Integer getPageSize() { + return pageSize.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue pageSize() { + return pageSize; + } + + @JsonIgnore + public List getDeliveryReports() { + return deliveryReports.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORTS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> deliveryReports() { + return deliveryReports; + } + + /** Return true if this DeliveryReportList object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + DeliveryReportListImpl deliveryReportList = (DeliveryReportListImpl) o; + return Objects.equals(this.count, deliveryReportList.count) + && Objects.equals(this.page, deliveryReportList.page) + && Objects.equals(this.pageSize, deliveryReportList.pageSize) + && Objects.equals(this.deliveryReports, deliveryReportList.deliveryReports); + } + + @Override + public int hashCode() { + return Objects.hash(count, page, pageSize, deliveryReports); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class DeliveryReportListImpl {\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append(" deliveryReports: ").append(toIndentedString(deliveryReports)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements DeliveryReportList.Builder { + OptionalValue count = OptionalValue.empty(); + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + OptionalValue> deliveryReports = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_COUNT) + public Builder setCount(Long count) { + this.count = OptionalValue.of(count); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE) + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + @JsonProperty(JSON_PROPERTY_DELIVERY_REPORTS) + public Builder setDeliveryReports(List deliveryReports) { + this.deliveryReports = OptionalValue.of(deliveryReports); + return this; + } + + public DeliveryReportList build() { + return new DeliveryReportListImpl(count, page, pageSize, deliveryReports); + } + } +} From f0857cdb7d9f8c635f725492380c1801b7de1664 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 3 Jan 2025 10:46:33 +0100 Subject: [PATCH 39/65] feat (SMS/DeliveryReports): Delivery Reports API --- .../sms/api/v1/DeliveryReportsService.java | 19 ++ .../sdk/domains/sms/api/v1/SMSService.java | 2 + .../v1/adapters/DeliveryReportsService.java | 64 ++++++ .../sms/api/v1/adapters/SMSService.java | 9 + .../deliveryreports/BatchDeliveryReport.java | 7 + .../RecipientDeliveryReport.java | 7 + .../response/ListDeliveryReportsResponse.java | 58 +++++ .../adapters/DeliveryReportsServiceTest.java | 211 ++++++++++++++++++ .../domains/sms/v1/DeliveryReportsSteps.java | 186 +++++++++++++++ .../sinch/sdk/e2e/domains/sms/v1/SmsIT.java | 1 + .../BatchDeliveryReportDtoTest.java | 58 +++++ .../RecipientDeliveryReportDtoTest.java | 58 +++++ .../com/sinch/sample/sms/v1/batches/Send.java | 3 +- .../sms/v1/batches/SendDeliveryFeedback.java | 4 +- .../sample/sms/v1/deliveryReports/Get.java | 33 +++ .../sms/v1/deliveryReports/GetForNumber.java | 33 +++ .../sample/sms/v1/deliveryReports/List.java | 45 ++++ 17 files changed, 794 insertions(+), 4 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/DeliveryReportsSteps.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportDtoTest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/GetForNumber.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/List.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java new file mode 100644 index 000000000..1ec62b306 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java @@ -0,0 +1,19 @@ +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; + +public interface DeliveryReportsService { + + BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters parameters) + throws ApiException; + + RecipientDeliveryReport getForNumber(String batchId, String recipient) throws ApiException; + + ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters parameters) + throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java index 1df50d22b..18e71bda1 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -5,4 +5,6 @@ public interface SMSService { BatchesService batches(); InboundsService inbounds(); + + DeliveryReportsService deliveryReports(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java new file mode 100644 index 000000000..5a6f66c76 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java @@ -0,0 +1,64 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.internal.DeliveryReportsApi; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal.DeliveryReportList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; +import com.sinch.sdk.models.SmsContext; +import java.util.Map; + +public class DeliveryReportsService + implements com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService { + + private final DeliveryReportsApi api; + + protected DeliveryReportsApi getApi() { + return this.api; + } + + public DeliveryReportsService( + String uriUUID, + SmsContext context, + HttpClient httpClient, + Map authManagers) { + this.api = + new DeliveryReportsApi( + httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); + } + + public BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters parameters) + throws ApiException { + + return getApi().get(batchId, parameters); + } + + public RecipientDeliveryReport getForNumber(String batchId, String recipient) + throws ApiException { + return getApi().getForNumber(batchId, recipient); + } + + public ListDeliveryReportsResponse list() throws ApiException { + return this.list(null); + } + + public ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters parameters) + throws ApiException { + + DeliveryReportList response = getApi().list(parameters); + + SMSCursorPageNavigator navigator = + new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); + + return new ListDeliveryReportsResponse( + this, new Page<>(parameters, response.getDeliveryReports(), navigator)); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index 8820f3056..3a4353bef 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -29,6 +29,7 @@ public class SMSService implements com.sinch.sdk.domains.sms.api.v1.SMSService { private BatchesService batches; private InboundsService inbounds; + private DeliveryReportsService deliveryReports; public SMSService( UnifiedCredentials credentials, @@ -95,4 +96,12 @@ public InboundsService inbounds() { } return this.inbounds; } + + @Override + public DeliveryReportsService deliveryReports() { + if (null == this.deliveryReports) { + this.deliveryReports = new DeliveryReportsService(uriUUID, context, httpClient, authManagers); + } + return this.deliveryReports; + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java new file mode 100644 index 000000000..3da384072 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java @@ -0,0 +1,7 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal.BatchDeliveryReportOneOfImpl; + +@JsonDeserialize(using = BatchDeliveryReportOneOfImpl.Deserializer.class) +public interface BatchDeliveryReport {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java new file mode 100644 index 000000000..46982891a --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java @@ -0,0 +1,7 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal.RecipientDeliveryReportOneOfImpl; + +@JsonDeserialize(using = RecipientDeliveryReportOneOfImpl.Deserializer.class) +public interface RecipientDeliveryReport {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java new file mode 100644 index 000000000..d0c18aa32 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java @@ -0,0 +1,58 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +public class ListDeliveryReportsResponse extends ListResponse { + + private final Page page; + private final DeliveryReportsService service; + private ListDeliveryReportsResponse nextPage; + + public ListDeliveryReportsResponse( + DeliveryReportsService service, + Page page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + + if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { + return false; + } + + if (null == nextPage) { + ListDeliveryReportsQueryParameters.Builder newParameters = + ListDeliveryReportsQueryParameters.builder(page.getParameters()); + newParameters.setPage(page.getNextPageToken()); + nextPage = service.list(newParameters.build()); + } + return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); + } + + public ListDeliveryReportsResponse nextPage() { + + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + + ListDeliveryReportsResponse response = nextPage; + nextPage = null; + return response; + } + + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "RecipientDeliveryReport{" + "page=" + page + '}'; + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java new file mode 100644 index 000000000..22f0f5c6f --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java @@ -0,0 +1,211 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.domains.sms.api.v1.internal.DeliveryReportsApi; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.EncodingType; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportMMS; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportSMS; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.QueryReportType; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal.DeliveryReportList; +import com.sinch.sdk.models.SmsContext; +import java.time.Instant; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Map; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +@TestWithResources +class DeliveryReportsServiceTest extends BaseTest { + + @Mock SmsContext context; + @Mock HttpClient httpClient; + @Mock Map authManagers; + + @Mock DeliveryReportsApi api; + DeliveryReportsService service; + String uriPartID = "foovalue"; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") + BatchDeliveryReport deliveryReportBatchSMSDto; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") + BatchDeliveryReport deliveryReportBatchMMSDto; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") + RecipientDeliveryReport deliveryReportRecipientSMSDto; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") + RecipientDeliveryReport deliveryReportRecipientMMSDto; + + @GivenJsonResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage0.json") + DeliveryReportList listDeliveryReportResponseDtoPage0; + + @GivenJsonResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage1.json") + DeliveryReportList listDeliveryReportResponseDtoPage1; + + @GivenJsonResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage2.json") + DeliveryReportList listDeliveryReportResponseDtoPage2; + + @BeforeEach + public void initMocks() { + service = spy(new DeliveryReportsService(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @Test + void getBatchDeliveryReportSMS() throws ApiException { + + BatchDeliveryReportQueryParameters queryParameters = + BatchDeliveryReportQueryParameters.builder() + .setCode( + Arrays.asList( + DeliveryReceiptErrorCode.from(456), DeliveryReceiptErrorCode.from(789))) + .setStatus(Arrays.asList(DeliveryStatus.from("foo status1"), DeliveryStatus.CANCELLED)) + .setType(QueryReportType.from("foo type")) + .build(); + + when(api.get(eq("foo binary batch id"), eq(queryParameters))) + .thenReturn(deliveryReportBatchSMSDto); + + BatchDeliveryReport response = service.get("foo binary batch id", queryParameters); + + TestHelpers.recursiveEquals(response, deliveryReportBatchSMSDto); + } + + @Test + void getBatchDeliveryReportMMS() throws ApiException { + + BatchDeliveryReportQueryParameters queryParameters = + BatchDeliveryReportQueryParameters.builder() + .setCode( + Arrays.asList( + DeliveryReceiptErrorCode.from(456), DeliveryReceiptErrorCode.from(789))) + .setStatus(Arrays.asList(DeliveryStatus.from("foo status1"), DeliveryStatus.CANCELLED)) + .setType(QueryReportType.from("foo type")) + .build(); + + when(api.get(eq("foo binary batch id"), eq(queryParameters))) + .thenReturn(deliveryReportBatchMMSDto); + + BatchDeliveryReport response = service.get("foo binary batch id", queryParameters); + + TestHelpers.recursiveEquals(response, deliveryReportBatchMMSDto); + } + + @Test + void getRecipientDeliveryReportSMS() throws ApiException { + + when(api.getForNumber(eq("foo binary batch id"), eq("foo number"))) + .thenReturn(deliveryReportRecipientSMSDto); + + RecipientDeliveryReport response = service.getForNumber("foo binary batch id", "foo number"); + + TestHelpers.recursiveEquals(response, deliveryReportRecipientSMSDto); + } + + @Test + void getRecipientDeliveryReportMMS() throws ApiException { + + when(api.getForNumber(eq("foo binary batch id"), eq("foo number"))) + .thenReturn(deliveryReportRecipientMMSDto); + + RecipientDeliveryReport response = service.getForNumber("foo binary batch id", "foo number"); + + TestHelpers.recursiveEquals(response, deliveryReportRecipientMMSDto); + } + + @Test + void list() throws ApiException { + + ListDeliveryReportsQueryParameters page1 = + ListDeliveryReportsQueryParameters.builder().setPage(1).build(); + ListDeliveryReportsQueryParameters page2 = + ListDeliveryReportsQueryParameters.builder().setPage(2).build(); + + when(api.list(eq(null))).thenReturn(listDeliveryReportResponseDtoPage0); + when(api.list(eq(page1))).thenReturn(listDeliveryReportResponseDtoPage1); + when(api.list(eq(page2))).thenReturn(listDeliveryReportResponseDtoPage2); + + ListDeliveryReportsResponse response = service.list(null); + + Iterator iterator = response.iterator(); + RecipientDeliveryReport item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + + TestHelpers.recursiveEquals( + item, + RecipientDeliveryReportSMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setRecipient("+44231235674") + .setCode(DeliveryReceiptErrorCode.DISPATCHED) + .setStatus(DeliveryStatus.DISPATCHED) + .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setOperator("operator") + .setAppliedOriginator("applied originator") + .setClientReference("client reference") + .setEncoding(EncodingType.from("encoding")) + .setNumberOfMessageParts(123) + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TestHelpers.recursiveEquals( + item, + RecipientDeliveryReportMMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setRecipient("+44231235674") + .setCode(DeliveryReceiptErrorCode.DISPATCHED) + .setStatus(DeliveryStatus.DISPATCHED) + .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setOperator("operator") + .setAppliedOriginator("applied originator") + .setClientReference("client reference") + .setEncoding(EncodingType.from("encoding")) + .setNumberOfMessageParts(123) + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + TestHelpers.recursiveEquals( + item, + RecipientDeliveryReportSMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setRecipient("+44231235674") + .setCode(DeliveryReceiptErrorCode.from(401)) + .setStatus(DeliveryStatus.DISPATCHED) + .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setOperator("operator") + .setAppliedOriginator("applied originator") + .setClientReference("client reference") + .setEncoding(EncodingType.from("encoding")) + .setNumberOfMessageParts(123) + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build()); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/DeliveryReportsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/DeliveryReportsSteps.java new file mode 100644 index 000000000..a7dfb1ca7 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/DeliveryReportsSteps.java @@ -0,0 +1,186 @@ +package com.sinch.sdk.e2e.domains.sms.v1; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportSMS; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.MessageDeliveryStatus; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportSMS; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.QueryReportType; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class DeliveryReportsSteps { + + DeliveryReportsService service; + + BatchDeliveryReport summaryReport; + BatchDeliveryReport fullReport; + RecipientDeliveryReport recipientReport; + ListDeliveryReportsResponse listOnePageResponse; + ListDeliveryReportsResponse listAllResponse; + ListDeliveryReportsResponse listAllByPageResponse; + + @Given("^the SMS service \"Delivery Reports\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().v1().deliveryReports(); + } + + @When("^I send a request to retrieve a summary SMS delivery report$") + public void getSummary() { + BatchDeliveryReportQueryParameters request = + BatchDeliveryReportQueryParameters.builder() + .setType(QueryReportType.SUMMARY) + .setStatus(Arrays.asList(DeliveryStatus.DELIVERED, DeliveryStatus.FAILED)) + .setCode( + Arrays.asList(DeliveryReceiptErrorCode.from(15), DeliveryReceiptErrorCode.from(0))) + .build(); + + summaryReport = service.get("foo", request); + } + + @When("^I send a request to retrieve a full SMS delivery report$") + public void getFull() { + BatchDeliveryReportQueryParameters request = + BatchDeliveryReportQueryParameters.builder().setType(QueryReportType.FULL).build(); + + fullReport = service.get("foo", request); + } + + @When("^I send a request to retrieve a recipient's delivery report$") + public void getRecipient() { + + recipientReport = service.getForNumber("foo", "+12345678"); + } + + @When("^I send a request to list the SMS delivery reports$") + public void listOnePage() { + ListDeliveryReportsQueryParameters request = + ListDeliveryReportsQueryParameters.builder().setPageSize(2).build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the SMS delivery reports$") + public void listAll() { + ListDeliveryReportsQueryParameters request = + ListDeliveryReportsQueryParameters.builder().setPageSize(2).build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the SMS delivery reports pages$") + public void listAllByPage() { + ListDeliveryReportsQueryParameters request = + ListDeliveryReportsQueryParameters.builder().setPageSize(2).build(); + + listAllByPageResponse = service.list(request); + } + + @Then("the response contains a summary SMS delivery report") + public void getSummaryResult() { + BatchDeliveryReport expected = + BatchDeliveryReportSMS.builder() + .setBatchId("01W4FFL35P4NC4K35SMSBATCH1") + .setClientReference("reference_e2e") + .setStatuses( + Arrays.asList( + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(15)) + .setCount(1) + .setStatus(DeliveryStatus.FAILED) + .build(), + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(0)) + .setCount(1) + .setStatus(DeliveryStatus.DELIVERED) + .build())) + .setTotalMessageCount(2) + .build(); + TestHelpers.recursiveEquals(summaryReport, expected); + } + + @Then("the response contains a full SMS delivery report") + public void getFullResult() { + BatchDeliveryReport expected = + BatchDeliveryReportSMS.builder() + .setBatchId("01W4FFL35P4NC4K35SMSBATCH1") + .setClientReference("reference_e2e") + .setStatuses( + Arrays.asList( + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(0)) + .setCount(1) + .setStatus(DeliveryStatus.DELIVERED) + .setRecipients(new HashSet<>(Collections.singletonList("12017777777"))) + .build(), + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(15)) + .setCount(1) + .setStatus(DeliveryStatus.FAILED) + .setRecipients(new HashSet<>(Collections.singletonList("12018888888"))) + .build())) + .setTotalMessageCount(2) + .build(); + TestHelpers.recursiveEquals(fullReport, expected); + } + + @Then("the response contains the recipient's delivery report details") + public void getRecipientResult() { + RecipientDeliveryReport expected = + RecipientDeliveryReportSMS.builder() + .setCreatedAt(Instant.parse("2024-06-06T13:06:27.833Z")) + .setBatchId("01W4FFL35P4NC4K35SMSBATCH1") + .setClientReference("reference_e2e") + .setCode(DeliveryReceiptErrorCode.from(0)) + .setOperatorStatusAt(Instant.parse("2024-06-06T13:06:00Z")) + .setRecipient("12017777777") + .setStatus(DeliveryStatus.DELIVERED) + .build(); + + TestHelpers.recursiveEquals(recipientReport, expected); + } + + @Then("the response contains \"{int}\" SMS delivery reports") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the SMS delivery reports list contains \"{int}\" SMS delivery reports") + public void listAllResult(int expected) { + ListDeliveryReportsResponse response = + null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the SMS delivery reports iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java index 4519cbf52..4470d682e 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java @@ -13,5 +13,6 @@ @IncludeEngines("cucumber") @SelectClasspathResource("features/sms/batches.feature") @SelectClasspathResource("features/sms/inbounds.feature") +@SelectClasspathResource("features/sms/delivery-reports.feature") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v1") public class SmsIT {} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportDtoTest.java new file mode 100644 index 000000000..ff88f67bd --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReportDtoTest.java @@ -0,0 +1,58 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import java.util.Collections; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class BatchDeliveryReportDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") + BatchDeliveryReport deliveryReportBatchSMSDto; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") + BatchDeliveryReport deliveryReportBatchMMSDto; + + public static BatchDeliveryReportSMS deliveryReportBatchSMS = + BatchDeliveryReportSMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setStatuses( + Collections.singletonList( + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(0)) + .setCount(1) + .setRecipients(Collections.singleton("44231235674")) + .setStatus(DeliveryStatus.DELIVERED) + .build())) + .setTotalMessageCount(1) + .setClientReference("a client reference") + .build(); + + public static BatchDeliveryReportMMS deliveryReportBatchMMS = + BatchDeliveryReportMMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setStatuses( + Collections.singletonList( + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(0)) + .setCount(1) + .setRecipients(Collections.singleton("44231235674")) + .setStatus(DeliveryStatus.DELIVERED) + .build())) + .setTotalMessageCount(1) + .setClientReference("a client reference") + .build(); + + @Test + void deserializeBatchDeliveryReportSMS() { + TestHelpers.recursiveEquals(deliveryReportBatchSMS, deliveryReportBatchSMSDto); + } + + @Test + void deserializeBatchDeliveryReportMMS() { + TestHelpers.recursiveEquals(deliveryReportBatchMMS, deliveryReportBatchMMSDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java new file mode 100644 index 000000000..e6d77ebfd --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java @@ -0,0 +1,58 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import java.time.Instant; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class RecipientDeliveryReportDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") + RecipientDeliveryReportSMS RecipientDeliveryReportSMSDto; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") + RecipientDeliveryReportMMS RecipientDeliveryReportMMSDto; + + public static RecipientDeliveryReportSMS deliveryReportRecipientSMS = + RecipientDeliveryReportSMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setClientReference("client reference") + .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setCode(DeliveryReceiptErrorCode.DISPATCHED) + .setRecipient("+44231235674") + .setStatus(DeliveryStatus.DISPATCHED) + .setAppliedOriginator("applied originator") + .setEncoding(EncodingType.from("encoding")) + .setNumberOfMessageParts(123) + .setOperator("operator") + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build(); + + public static RecipientDeliveryReportMMS deliveryReportRecipientMMS = + RecipientDeliveryReportMMS.builder() + .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") + .setClientReference("client reference") + .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) + .setCode(DeliveryReceiptErrorCode.DISPATCHED) + .setRecipient("+44231235674") + .setStatus(DeliveryStatus.DISPATCHED) + .setAppliedOriginator("applied originator") + .setEncoding(EncodingType.from("encoding")) + .setNumberOfMessageParts(123) + .setOperator("operator") + .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) + .build(); + + @Test + void deserializeDeliveryReportRecipientSMS() { + TestHelpers.recursiveEquals(deliveryReportRecipientSMS, RecipientDeliveryReportSMSDto); + } + + @Test + void deserializeDeliveryReportRecipientMMS() { + TestHelpers.recursiveEquals(deliveryReportRecipientMMS, RecipientDeliveryReportMMSDto); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java index f3abc50a3..118003a03 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/Send.java @@ -56,7 +56,8 @@ public void run() { .setClientReference("a client reference") .setFrom("+33123456789") .setParameters(parameters) - .setDeliveryReport(DeliveryReportType.FULL); + .setFeedbackEnabled(true) + .setDeliveryReport(DeliveryReportType.PER_RECIPIENT_FINAL); // Overload default dashboard webhooks URL if defined webhooksSmsPath.ifPresent(builder::setCallbackUrl); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java index 7ea8acb24..b1b8ad002 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/batches/SendDeliveryFeedback.java @@ -29,9 +29,7 @@ public void run() { LOGGER.info("Send Delivery Feedback for batch ID:" + batchId); SendDeliveryFeedbackRequest request = - SendDeliveryFeedbackRequest.builder() - .setRecipients(Arrays.asList("+1234567890", "+0987654321")) - .build(); + SendDeliveryFeedbackRequest.builder().setRecipients(Arrays.asList(phoneNumber)).build(); service.sendDeliveryFeedback(batchId, request); LOGGER.info("Done"); } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java new file mode 100644 index 000000000..c4b60e49e --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java @@ -0,0 +1,33 @@ +package com.sinch.sample.sms.v1.deliveryReports; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + DeliveryReportsService service = client.sms().v1().deliveryReports(); + + LOGGER.info("Get for :" + batchId); + + BatchDeliveryReport response = service.get(batchId, null); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/GetForNumber.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/GetForNumber.java new file mode 100644 index 000000000..700f565ac --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/GetForNumber.java @@ -0,0 +1,33 @@ +package com.sinch.sample.sms.v1.deliveryReports; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import java.io.IOException; +import java.util.logging.Logger; + +public class GetForNumber extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public GetForNumber() throws IOException {} + + public static void main(String[] args) { + try { + new GetForNumber().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + DeliveryReportsService service = client.sms().v1().deliveryReports(); + + LOGGER.info("Get for: " + phoneNumber); + + RecipientDeliveryReport response = service.getForNumber(batchId, phoneNumber); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/List.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/List.java new file mode 100644 index 000000000..0cd7577a6 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/List.java @@ -0,0 +1,45 @@ +package com.sinch.sample.sms.v1.deliveryReports; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import java.io.IOException; +import java.util.Arrays; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + DeliveryReportsService service = client.sms().v1().deliveryReports(); + + LOGGER.info("List Delivery Reports"); + + LOGGER.info("Response:"); + service + .list( + ListDeliveryReportsQueryParameters.builder() + .setStatus(Arrays.asList(DeliveryStatus.CANCELLED, DeliveryStatus.FAILED)) + .setCode( + Arrays.asList( + DeliveryReceiptErrorCode.from(0), DeliveryReceiptErrorCode.DISPATCHED)) + .build()) + .iterator() + .forEachRemaining(f -> LOGGER.info(f.toString())); + } +} From b3e92eaf6d33701270d74a1d0dbadf42de7ea3d9 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 10 Jan 2025 11:29:47 +0100 Subject: [PATCH 40/65] feat (SMS/DeliveryReport): Elegant function for delivery report 'get' --- .../sdk/domains/sms/api/v1/DeliveryReportsService.java | 4 ++++ .../sms/api/v1/adapters/DeliveryReportsService.java | 5 +++++ .../api/v1/adapters/DeliveryReportsServiceTest.java | 10 ++++++++++ .../com/sinch/sample/sms/v1/deliveryReports/Get.java | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java index 1ec62b306..a8a909c17 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java @@ -9,11 +9,15 @@ public interface DeliveryReportsService { + BatchDeliveryReport get(String batchId) throws ApiException; + BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters parameters) throws ApiException; RecipientDeliveryReport getForNumber(String batchId, String recipient) throws ApiException; + ListDeliveryReportsResponse list() throws ApiException; + ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters parameters) throws ApiException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java index 5a6f66c76..bac9bd64b 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java @@ -35,6 +35,11 @@ public DeliveryReportsService( httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); } + public BatchDeliveryReport get(String batchId) throws ApiException { + + return getApi().get(batchId); + } + public BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters parameters) throws ApiException { diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java index 22f0f5c6f..ad8f03f2f 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java @@ -76,6 +76,16 @@ public void initMocks() { doReturn(api).when(service).getApi(); } + @Test + void getSimplifiedDeliveryReport() throws ApiException { + + when(api.get(eq("foo binary batch id"))).thenReturn(deliveryReportBatchSMSDto); + + BatchDeliveryReport response = service.get("foo binary batch id"); + + TestHelpers.recursiveEquals(response, deliveryReportBatchSMSDto); + } + @Test void getBatchDeliveryReportSMS() throws ApiException { diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java index c4b60e49e..dbfe3ba8c 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/deliveryReports/Get.java @@ -26,7 +26,7 @@ public void run() { LOGGER.info("Get for :" + batchId); - BatchDeliveryReport response = service.get(batchId, null); + BatchDeliveryReport response = service.get(batchId); LOGGER.info("Response :" + response); } From 5ac343d4f57b489d94bc2f6e16ac89f3b759e192 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 10 Jan 2025 11:30:57 +0100 Subject: [PATCH 41/65] feat (SMS): Generated sources with elegant function stripped from query paramerters --- .../sms/api/v1/internal/BatchesApi.java | 25 +++++++++++++++ .../api/v1/internal/DeliveryReportsApi.java | 31 +++++++++++++++++-- .../sms/api/v1/internal/InboundsApi.java | 13 ++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java index dfd0e385d..dacfeb320 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java @@ -139,6 +139,19 @@ private HttpRequest cancelRequestBuilder(String batchId) throws ApiException { localVarAuthNames); } + /** + * Dry run This operation will perform a dry run of a batch which calculates the bodies and number + * of parts for all messages in the batch without actually sending any messages. + * + * @param sendRequest (optional) + * @return DryRunResponse + * @throws ApiException if fails to make API call + */ + public DryRunResponse dryRun(BatchRequest sendRequest) throws ApiException { + + return dryRun(null, sendRequest); + } + /** * Dry run This operation will perform a dry run of a batch which calculates the bodies and number * of parts for all messages in the batch without actually sending any messages. @@ -302,6 +315,18 @@ private HttpRequest getRequestBuilder(String batchId) throws ApiException { localVarAuthNames); } + /** + * List Batches With the list operation you can list batch messages created in the last 14 days + * that you have created. This operation supports pagination. + * + * @return ApiBatchList + * @throws ApiException if fails to make API call + */ + public ApiBatchList list() throws ApiException { + + return list(null); + } + /** * List Batches With the list operation you can list batch messages created in the last 14 days * that you have created. This operation supports pagination. diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java index c84ab9bfe..1c3649ab4 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java @@ -63,8 +63,23 @@ public DeliveryReportsApi( /** * Retrieve a delivery report Delivery reports can be retrieved even if no callback was requested. * The difference between a summary and a full report is only that the full report contains the - * phone numbers in [>E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537\") - * format for each status code. + * phone numbers in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format for + * each status code. + * + * @param batchId The batch ID you received from sending a message. (required) + * @return BatchDeliveryReport + * @throws ApiException if fails to make API call + */ + public BatchDeliveryReport get(String batchId) throws ApiException { + + return get(batchId, null); + } + + /** + * Retrieve a delivery report Delivery reports can be retrieved even if no callback was requested. + * The difference between a summary and a full report is only that the full report contains the + * phone numbers in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format for + * each status code. * * @param batchId The batch ID you received from sending a message. (required) * @param queryParameter (optional) @@ -245,6 +260,18 @@ private HttpRequest getForNumberRequestBuilder(String batchId, String recipientM localVarAuthNames); } + /** + * Retrieve a list of delivery reports Get a list of finished delivery reports. This operation + * supports pagination. + * + * @return DeliveryReportList + * @throws ApiException if fails to make API call + */ + public DeliveryReportList list() throws ApiException { + + return list(null); + } + /** * Retrieve a list of delivery reports Get a list of finished delivery reports. This operation * supports pagination. diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java index 6bd16ffe7..b47b57771 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java @@ -60,6 +60,19 @@ public InboundsApi( this.servicePlanId = servicePlanId; } + /** + * List incoming messages With the list operation, you can list all inbound messages that you have + * received. This operation supports pagination. Inbounds are returned in reverse chronological + * order. + * + * @return ApiInboundList + * @throws ApiException if fails to make API call + */ + public ApiInboundList list() throws ApiException { + + return list(null); + } + /** * List incoming messages With the list operation, you can list all inbound messages that you have * received. This operation supports pagination. Inbounds are returned in reverse chronological From a485dc1d75783b32b3f58233d080c60a2bf24a15 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 8 Jan 2025 13:42:02 +0100 Subject: [PATCH 42/65] feat (SMS/Webhooks): Webhooks API --- .../sdk/domains/sms/api/v1/SMSService.java | 2 + .../domains/sms/api/v1/WebHooksService.java | 9 ++ .../sms/api/v1/adapters/SMSService.java | 9 ++ .../sms/api/v1/adapters/WebHooksService.java | 18 +++ .../deliveryreports/BatchDeliveryReport.java | 2 +- .../v1/deliveryreports/DeliveryReport.java | 5 + .../RecipientDeliveryReport.java | 2 +- .../models/v1/inbounds/InboundMessage.java | 3 +- .../sms/models/v1/webhooks/SmsEvent.java | 8 + .../api/v1/adapters/WebHooksServiceTest.java | 98 ++++++++++++ .../sinch/sdk/e2e/domains/sms/v1/SmsIT.java | 1 + .../sdk/e2e/domains/sms/v1/WebhooksSteps.java | 141 ++++++++++++++++++ .../RecipientDeliveryReportDtoTest.java | 4 +- .../v1/inbounds/InboundMessageDtoTest.java | 16 +- .../v1/webhooks/WebhookEventDtoTest.java | 79 ++++++++++ 15 files changed, 384 insertions(+), 13 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/webhooks/WebhookEventDtoTest.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java index 18e71bda1..69a153d23 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -7,4 +7,6 @@ public interface SMSService { InboundsService inbounds(); DeliveryReportsService deliveryReports(); + + WebHooksService webhooks(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java new file mode 100644 index 000000000..72fab711c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java @@ -0,0 +1,9 @@ +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiMappingException; +import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; + +public interface WebHooksService { + + SmsEvent parse(String jsonPayload) throws ApiMappingException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index 3a4353bef..d6f08f978 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -30,6 +30,7 @@ public class SMSService implements com.sinch.sdk.domains.sms.api.v1.SMSService { private BatchesService batches; private InboundsService inbounds; private DeliveryReportsService deliveryReports; + private WebHooksService webhooks; public SMSService( UnifiedCredentials credentials, @@ -104,4 +105,12 @@ public DeliveryReportsService deliveryReports() { } return this.deliveryReports; } + + @Override + public WebHooksService webhooks() { + if (null == this.webhooks) { + this.webhooks = new WebHooksService(); + } + return this.webhooks; + } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java new file mode 100644 index 000000000..2820c2233 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java @@ -0,0 +1,18 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.core.exceptions.ApiMappingException; +import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; + +public class WebHooksService implements com.sinch.sdk.domains.sms.api.v1.WebHooksService { + + public SmsEvent parse(String jsonPayload) throws ApiMappingException { + + try { + return Mapper.getInstance().readValue(jsonPayload, SmsEvent.class); + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java index 3da384072..d474942eb 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java @@ -4,4 +4,4 @@ import com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal.BatchDeliveryReportOneOfImpl; @JsonDeserialize(using = BatchDeliveryReportOneOfImpl.Deserializer.class) -public interface BatchDeliveryReport {} +public interface BatchDeliveryReport extends DeliveryReport {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java new file mode 100644 index 000000000..ab999d211 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java @@ -0,0 +1,5 @@ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; + +import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; + +public interface DeliveryReport extends SmsEvent {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java index 46982891a..44d2265e3 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java @@ -4,4 +4,4 @@ import com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal.RecipientDeliveryReportOneOfImpl; @JsonDeserialize(using = RecipientDeliveryReportOneOfImpl.Deserializer.class) -public interface RecipientDeliveryReport {} +public interface RecipientDeliveryReport extends DeliveryReport {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java index d3100622d..a689da166 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.InboundInternalImpl; +import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; @JsonDeserialize(using = InboundInternalImpl.Deserializer.class) -public interface InboundMessage {} +public interface InboundMessage extends SmsEvent {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java new file mode 100644 index 000000000..48da3fbfc --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java @@ -0,0 +1,8 @@ +package com.sinch.sdk.domains.sms.models.v1.webhooks; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.webhooks.internal.WebhookEventOneOfImpl; + +/** Interface defining a WebHook event */ +@JsonDeserialize(using = WebhookEventOneOfImpl.Deserializer.class) +public interface SmsEvent {} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java new file mode 100644 index 000000000..63c50a31f --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java @@ -0,0 +1,98 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportDtoTest; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportDtoTest; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessageDtoTest; +import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +import org.junit.jupiter.api.Test; +import org.mockito.InjectMocks; + +@TestWithResources +public class WebHooksServiceTest extends BaseTest { + + @GivenTextResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") + String loadedInboundBinaryEvent; + + @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") + String loadedInboundTextEvent; + + @GivenTextResource("/domains/sms/v1/inbounds/InboundMediaDto.json") + String loadedInboundMediaEvent; + + @GivenTextResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") + String loadedBatchDeliveryReportSMSEvent; + + @GivenTextResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") + String loadedBatchDeliveryReportMMSEvent; + + @GivenTextResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") + String loadedRecipientDeliveryReportSMSEvent; + + @GivenTextResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") + String loadedRecipientDeliveryReportMMSEvent; + + @InjectMocks WebHooksService service; + + @Test + void incomingSMSBinary() throws ApiException { + + SmsEvent response = service.parse(loadedInboundBinaryEvent); + + TestHelpers.recursiveEquals(InboundMessageDtoTest.binaryDTO, response); + } + + @Test + void incomingSMSText() throws ApiException { + + SmsEvent response = service.parse(loadedInboundTextEvent); + + TestHelpers.recursiveEquals(InboundMessageDtoTest.textDTO, response); + } + + @Test + void incomingSMSMedia() throws ApiException { + + SmsEvent response = service.parse(loadedInboundMediaEvent); + + TestHelpers.recursiveEquals(InboundMessageDtoTest.mediaDTO, response); + } + + @Test + void deliveryReportRecipientDeliveryReportSms() throws ApiException { + + SmsEvent response = service.parse(loadedRecipientDeliveryReportSMSEvent); + + TestHelpers.recursiveEquals( + RecipientDeliveryReportDtoTest.deliveryReportRecipientSMS, response); + } + + @Test + void deliveryReportRecipientDeliveryReportMms() throws ApiException { + + SmsEvent response = service.parse(loadedRecipientDeliveryReportMMSEvent); + + TestHelpers.recursiveEquals( + RecipientDeliveryReportDtoTest.deliveryReportRecipientMMS, response); + } + + @Test + void deliveryReportBatchDeliveryReportSms() throws ApiException { + + SmsEvent response = service.parse(loadedBatchDeliveryReportSMSEvent); + + TestHelpers.recursiveEquals(BatchDeliveryReportDtoTest.deliveryReportBatchSMS, response); + } + + @Test + void deliveryReportBatchDeliveryReportMms() throws ApiException { + + SmsEvent response = service.parse(loadedBatchDeliveryReportMMSEvent); + + TestHelpers.recursiveEquals(BatchDeliveryReportDtoTest.deliveryReportBatchMMS, response); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java index 4470d682e..2e8feba32 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java @@ -14,5 +14,6 @@ @SelectClasspathResource("features/sms/batches.feature") @SelectClasspathResource("features/sms/inbounds.feature") @SelectClasspathResource("features/sms/delivery-reports.feature") +@SelectClasspathResource("features/sms/webhooks.feature") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v1") public class SmsIT {} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java new file mode 100644 index 000000000..23a0d9475 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java @@ -0,0 +1,141 @@ +package com.sinch.sdk.e2e.domains.sms.v1; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.api.v1.WebHooksService; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportSMS; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.MessageDeliveryStatus; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportSMS; +import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; +import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +import com.sinch.sdk.e2e.Config; +import com.sinch.sdk.e2e.domains.WebhooksHelper; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.io.IOException; +import java.net.URL; +import java.time.Instant; +import java.util.Arrays; +import java.util.HashSet; + +public class WebhooksSteps { + + static final String WEBHOOKS_PATH_PREFIX = "/webhooks/sms"; + static final String WEBHOOKS_URL = Config.SMS_HOST_NAME + WEBHOOKS_PATH_PREFIX; + + WebHooksService service; + WebhooksHelper.Response incoming; + WebhooksHelper.Response deliveryReport; + WebhooksHelper.Response deliveryReportRecipientDelivered; + WebhooksHelper.Response deliveryReportRecipientAborted; + + @Given("^the SMS Webhooks handler is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().v1().webhooks(); + } + + @When("^I send a request to trigger an \"incoming SMS\" event") + public void incoming() throws IOException { + + incoming = WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/incoming-sms"), service::parse); + } + + @When("^I send a request to trigger an \"SMS delivery report\" event") + public void deliveryReport() throws IOException { + + deliveryReport = + WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/delivery-report-sms"), service::parse); + } + + @When( + "^I send a request to trigger an \"SMS recipient delivery report\" event with the status" + + " \"Delivered\"") + public void deliveryReportRecipientDelivered() throws IOException { + + deliveryReportRecipientDelivered = + WebhooksHelper.callURL( + new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-delivered"), service::parse); + } + + @When( + "^I send a request to trigger an \"SMS recipient delivery report\" event with the status" + + " \"Aborted\"") + public void deliveryReportRecipientAborted() throws IOException { + + deliveryReportRecipientAborted = + WebhooksHelper.callURL( + new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-aborted"), service::parse); + } + + @Then("the SMS event describes an \"incoming SMS\" event") + public void incomingResult() { + SmsEvent expected = + TextMessage.builder() + .setBody("Hello John! 👋") + .setFrom("12015555555") + .setId("01W4FFL35P4NC4K35SMSBATCH8") + .setOperatorId("311071") + .setReceivedAt(Instant.parse("2024-06-06T07:52:37.386Z")) + .setTo("12017777777") + .build(); + + TestHelpers.recursiveEquals(incoming.event, expected); + } + + @Then("the SMS event describes an \"SMS delivery report\" event") + public void deliveryReportResult() { + SmsEvent expected = + BatchDeliveryReportSMS.builder() + .setBatchId("01W4FFL35P4NC4K35SMSBATCH8") + .setClientReference("client-ref") + .setStatuses( + Arrays.asList( + MessageDeliveryStatus.builder() + .setCode(DeliveryReceiptErrorCode.from(0)) + .setCount(2) + .setRecipients(new HashSet<>(Arrays.asList("12017777777", "33612345678"))) + .setStatus(DeliveryStatus.DELIVERED) + .build())) + .setTotalMessageCount(2) + .build(); + + TestHelpers.recursiveEquals(deliveryReport.event, expected); + } + + @Then( + "the SMS event describes an SMS recipient delivery report event with the status" + + " \"Delivered\"") + public void deliveryReportRecipientDeliveredResult() { + SmsEvent expected = + RecipientDeliveryReportSMS.builder() + .setCreatedAt(Instant.parse("2024-06-06T08:17:19.210Z")) + .setBatchId("01W4FFL35P4NC4K35SMSBATCH9") + .setClientReference("client-ref") + .setCode(DeliveryReceiptErrorCode.from(0)) + .setOperatorStatusAt(Instant.parse("2024-06-06T08:17:00Z")) + .setRecipient("12017777777") + .setStatus(DeliveryStatus.DELIVERED) + .build(); + + TestHelpers.recursiveEquals(deliveryReportRecipientDelivered.event, expected); + } + + @Then( + "the SMS event describes an SMS recipient delivery report event with the status \"Aborted\"") + public void deliveryReportRecipientAbortedResult() { + SmsEvent expected = + RecipientDeliveryReportSMS.builder() + .setCreatedAt(Instant.parse("2024-06-06T08:17:15.603Z")) + .setBatchId("01W4FFL35P4NC4K35SMSBATCH9") + .setClientReference("client-ref") + .setCode(DeliveryReceiptErrorCode.UNPROVISIONED_REGION) + .setRecipient("12010000000") + .setStatus(DeliveryStatus.ABORTED) + .build(); + + TestHelpers.recursiveEquals(deliveryReportRecipientAborted.event, expected); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java index e6d77ebfd..75a2ab47c 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReportDtoTest.java @@ -11,10 +11,10 @@ public class RecipientDeliveryReportDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") - RecipientDeliveryReportSMS RecipientDeliveryReportSMSDto; + RecipientDeliveryReport RecipientDeliveryReportSMSDto; @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") - RecipientDeliveryReportMMS RecipientDeliveryReportMMSDto; + RecipientDeliveryReport RecipientDeliveryReportMMSDto; public static RecipientDeliveryReportSMS deliveryReportRecipientSMS = RecipientDeliveryReportSMS.builder() diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java index 0340ec5ac..3289c512d 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessageDtoTest.java @@ -3,13 +3,13 @@ import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; import java.time.Instant; import java.util.Arrays; -import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; @TestWithResources -class InboundMessageDtoTest extends BaseTest { +public class InboundMessageDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") InboundMessage loadedBinaryMessage; @@ -20,7 +20,7 @@ class InboundMessageDtoTest extends BaseTest { @GivenJsonResource("/domains/sms/v1/inbounds/InboundMediaDto.json") InboundMessage loadedMediaMessage; - BinaryMessage binaryDTO = + public static BinaryMessage binaryDTO = BinaryMessage.builder() .setClientReference("a client reference") .setFrom("+11203494390") @@ -33,7 +33,7 @@ class InboundMessageDtoTest extends BaseTest { .setUdh("foo udh") .build(); - TextMessage textDTO = + public static TextMessage textDTO = TextMessage.builder() .setClientReference("a client reference") .setFrom("+11203494390") @@ -45,7 +45,7 @@ class InboundMessageDtoTest extends BaseTest { .setBody("a body") .build(); - MediaMessage mediaDTO = + public static MediaMessage mediaDTO = MediaMessage.builder() .setClientReference("a client reference") .setFrom("+11203494390") @@ -72,18 +72,18 @@ class InboundMessageDtoTest extends BaseTest { @Test void deserializeBinaryMessage() { - Assertions.assertThat(loadedBinaryMessage).usingRecursiveComparison().isEqualTo(binaryDTO); + TestHelpers.recursiveEquals(binaryDTO, loadedBinaryMessage); } @Test void deserializeTextMessage() { - Assertions.assertThat(loadedTextMessage).usingRecursiveComparison().isEqualTo(textDTO); + TestHelpers.recursiveEquals(textDTO, loadedTextMessage); } @Test void deserializeMediaMessage() { - Assertions.assertThat(loadedMediaMessage).usingRecursiveComparison().isEqualTo(mediaDTO); + TestHelpers.recursiveEquals(mediaDTO, loadedMediaMessage); } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/webhooks/WebhookEventDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/webhooks/WebhookEventDtoTest.java new file mode 100644 index 000000000..9450e2f18 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/webhooks/WebhookEventDtoTest.java @@ -0,0 +1,79 @@ +package com.sinch.sdk.domains.sms.models.v1.webhooks; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportDtoTest; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportDtoTest; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessageDtoTest; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class WebhookEventDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") + SmsEvent loadedInboundBinaryEvent; + + @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") + SmsEvent loadedInboundTextEvent; + + @GivenJsonResource("/domains/sms/v1/inbounds/InboundMediaDto.json") + SmsEvent loadedInboundMediaEvent; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") + SmsEvent loadedBatchDeliveryReportSMSEvent; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") + SmsEvent loadedBatchDeliveryReportMMSEvent; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") + SmsEvent loadedRecipientDeliveryReportSMSEvent; + + @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") + SmsEvent loadedRecipientDeliveryReportMMSEvent; + + @Test + void deserializeBinaryMessage() { + + TestHelpers.recursiveEquals(InboundMessageDtoTest.binaryDTO, loadedInboundBinaryEvent); + } + + @Test + void deserializeTextMessage() { + + TestHelpers.recursiveEquals(InboundMessageDtoTest.textDTO, loadedInboundTextEvent); + } + + @Test + void deserializeMediaMessage() { + + TestHelpers.recursiveEquals(InboundMessageDtoTest.mediaDTO, loadedInboundMediaEvent); + } + + @Test + void deserializeBatchDeliveryReportSMS() { + TestHelpers.recursiveEquals( + BatchDeliveryReportDtoTest.deliveryReportBatchSMS, loadedBatchDeliveryReportSMSEvent); + } + + @Test + void deserializeBatchDeliveryReportMMS() { + TestHelpers.recursiveEquals( + BatchDeliveryReportDtoTest.deliveryReportBatchMMS, loadedBatchDeliveryReportMMSEvent); + } + + @Test + void deserializeDeliveryReportRecipientSMS() { + TestHelpers.recursiveEquals( + RecipientDeliveryReportDtoTest.deliveryReportRecipientSMS, + loadedRecipientDeliveryReportSMSEvent); + } + + @Test + void deserializeDeliveryReportRecipientMMS() { + TestHelpers.recursiveEquals( + RecipientDeliveryReportDtoTest.deliveryReportRecipientMMS, + loadedRecipientDeliveryReportMMSEvent); + } +} From 820d64a5a2b4962d475a462dda6fd38c03d2ab08 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 9 Jan 2025 12:17:52 +0100 Subject: [PATCH 43/65] feat (SMS/Webhooks): Generated files --- .../webhooks/internal/WebhookEventOneOf.java | 16 + .../internal/WebhookEventOneOfImpl.java | 718 ++++++++++++++++++ 2 files changed, 734 insertions(+) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOf.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOfImpl.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOf.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOf.java new file mode 100644 index 000000000..dbbef701f --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOf.java @@ -0,0 +1,16 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.webhooks.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize(using = WebhookEventOneOfImpl.WebhookEventOneOfImplDeserializer.class) +public interface WebhookEventOneOf {} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOfImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOfImpl.java new file mode 100644 index 000000000..ce37ce28d --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/internal/WebhookEventOneOfImpl.java @@ -0,0 +1,718 @@ +package com.sinch.sdk.domains.sms.models.v1.webhooks.internal; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.sinch.sdk.core.models.AbstractOpenApiSchema; +import com.sinch.sdk.core.utils.databind.JSONNavigator; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportMMSImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportSMSImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportMMSImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportSMSImpl; +import com.sinch.sdk.domains.sms.models.v1.inbounds.BinaryMessageImpl; +import com.sinch.sdk.domains.sms.models.v1.inbounds.MediaMessageImpl; +import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessageImpl; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +@JsonDeserialize(using = WebhookEventOneOfImpl.WebhookEventOneOfImplDeserializer.class) +@JsonSerialize(using = WebhookEventOneOfImpl.WebhookEventOneOfImplSerializer.class) +public class WebhookEventOneOfImpl extends AbstractOpenApiSchema implements WebhookEventOneOf { + private static final Logger log = Logger.getLogger(WebhookEventOneOfImpl.class.getName()); + + public static final class WebhookEventOneOfImplSerializer + extends StdSerializer { + private static final long serialVersionUID = 1L; + + public WebhookEventOneOfImplSerializer(Class t) { + super(t); + } + + public WebhookEventOneOfImplSerializer() { + this(null); + } + + @Override + public void serialize( + WebhookEventOneOfImpl value, JsonGenerator jgen, SerializerProvider provider) + throws IOException, JsonProcessingException { + jgen.writeObject(value.getActualInstance()); + } + } + + public static final class WebhookEventOneOfImplDeserializer + extends StdDeserializer { + + private static final long serialVersionUID = 1L; + + public WebhookEventOneOfImplDeserializer() { + this(WebhookEventOneOfImpl.class); + } + + public WebhookEventOneOfImplDeserializer(Class vc) { + super(vc); + } + + @Override + public WebhookEventOneOfImpl deserialize(JsonParser jp, DeserializationContext ctxt) + throws IOException, JsonProcessingException { + JsonNode tree = jp.readValueAsTree(); + Object deserialized = null; + WebhookEventOneOfImpl newWebhookEventOneOfImpl = new WebhookEventOneOfImpl(); + Map result2 = + tree.traverse(jp.getCodec()).readValueAs(new TypeReference>() {}); + String discriminatorValue = (String) result2.get("type"); + switch (discriminatorValue) { + case "delivery_report_mms": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportMMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "delivery_report_sms": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportSMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "mo_binary": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryMessageImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "mo_media": + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaMessageImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "mo_text": + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextMessageImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "recipient_delivery_report_mms": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportMMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "recipient_delivery_report_sms": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportSMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "BatchDeliveryReportMMS": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportMMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "BatchDeliveryReportSMS": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportSMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "MOBinary": + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryMessageImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "MOMedia": + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaMessageImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "MOText": + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextMessageImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "RecipientDeliveryReportMMS": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportMMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + case "RecipientDeliveryReportSMS": + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportSMSImpl.class); + newWebhookEventOneOfImpl.setActualInstance(deserialized); + return newWebhookEventOneOfImpl; + default: + log.log( + Level.WARNING, + String.format( + "Failed to lookup discriminator value `%s` for WebhookEventOneOfImpl. Possible" + + " values: delivery_report_mms delivery_report_sms mo_binary mo_media" + + " mo_text recipient_delivery_report_mms recipient_delivery_report_sms" + + " BatchDeliveryReportMMS BatchDeliveryReportSMS MOBinary MOMedia MOText" + + " RecipientDeliveryReportMMS RecipientDeliveryReportSMS", + discriminatorValue)); + } + + boolean typeCoercion = ctxt.isEnabled(MapperFeature.ALLOW_COERCION_OF_SCALARS); + int match = 0; + JsonToken token = tree.traverse(jp.getCodec()).nextToken(); + // deserialize BatchDeliveryReportMMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchDeliveryReportMMSImpl.class.equals(Integer.class) + || BatchDeliveryReportMMSImpl.class.equals(Long.class) + || BatchDeliveryReportMMSImpl.class.equals(Float.class) + || BatchDeliveryReportMMSImpl.class.equals(Double.class) + || BatchDeliveryReportMMSImpl.class.equals(Boolean.class) + || BatchDeliveryReportMMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchDeliveryReportMMSImpl.class.equals(Integer.class) + || BatchDeliveryReportMMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchDeliveryReportMMSImpl.class.equals(Float.class) + || BatchDeliveryReportMMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchDeliveryReportMMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchDeliveryReportMMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportMMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchDeliveryReportMMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchDeliveryReportMMSImpl'", e); + } + + // deserialize BatchDeliveryReportSMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BatchDeliveryReportSMSImpl.class.equals(Integer.class) + || BatchDeliveryReportSMSImpl.class.equals(Long.class) + || BatchDeliveryReportSMSImpl.class.equals(Float.class) + || BatchDeliveryReportSMSImpl.class.equals(Double.class) + || BatchDeliveryReportSMSImpl.class.equals(Boolean.class) + || BatchDeliveryReportSMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BatchDeliveryReportSMSImpl.class.equals(Integer.class) + || BatchDeliveryReportSMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BatchDeliveryReportSMSImpl.class.equals(Float.class) + || BatchDeliveryReportSMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BatchDeliveryReportSMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BatchDeliveryReportSMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BatchDeliveryReportSMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BatchDeliveryReportSMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BatchDeliveryReportSMSImpl'", e); + } + + // deserialize BinaryMessageImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (BinaryMessageImpl.class.equals(Integer.class) + || BinaryMessageImpl.class.equals(Long.class) + || BinaryMessageImpl.class.equals(Float.class) + || BinaryMessageImpl.class.equals(Double.class) + || BinaryMessageImpl.class.equals(Boolean.class) + || BinaryMessageImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((BinaryMessageImpl.class.equals(Integer.class) + || BinaryMessageImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((BinaryMessageImpl.class.equals(Float.class) + || BinaryMessageImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (BinaryMessageImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (BinaryMessageImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(BinaryMessageImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'BinaryMessageImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'BinaryMessageImpl'", e); + } + + // deserialize MediaMessageImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (MediaMessageImpl.class.equals(Integer.class) + || MediaMessageImpl.class.equals(Long.class) + || MediaMessageImpl.class.equals(Float.class) + || MediaMessageImpl.class.equals(Double.class) + || MediaMessageImpl.class.equals(Boolean.class) + || MediaMessageImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((MediaMessageImpl.class.equals(Integer.class) + || MediaMessageImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((MediaMessageImpl.class.equals(Float.class) + || MediaMessageImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (MediaMessageImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (MediaMessageImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(MediaMessageImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'MediaMessageImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'MediaMessageImpl'", e); + } + + // deserialize RecipientDeliveryReportMMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (RecipientDeliveryReportMMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportMMSImpl.class.equals(Long.class) + || RecipientDeliveryReportMMSImpl.class.equals(Float.class) + || RecipientDeliveryReportMMSImpl.class.equals(Double.class) + || RecipientDeliveryReportMMSImpl.class.equals(Boolean.class) + || RecipientDeliveryReportMMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((RecipientDeliveryReportMMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportMMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((RecipientDeliveryReportMMSImpl.class.equals(Float.class) + || RecipientDeliveryReportMMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (RecipientDeliveryReportMMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (RecipientDeliveryReportMMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportMMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'RecipientDeliveryReportMMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log( + Level.FINER, "Input data does not match schema 'RecipientDeliveryReportMMSImpl'", e); + } + + // deserialize RecipientDeliveryReportSMSImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (RecipientDeliveryReportSMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportSMSImpl.class.equals(Long.class) + || RecipientDeliveryReportSMSImpl.class.equals(Float.class) + || RecipientDeliveryReportSMSImpl.class.equals(Double.class) + || RecipientDeliveryReportSMSImpl.class.equals(Boolean.class) + || RecipientDeliveryReportSMSImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((RecipientDeliveryReportSMSImpl.class.equals(Integer.class) + || RecipientDeliveryReportSMSImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((RecipientDeliveryReportSMSImpl.class.equals(Float.class) + || RecipientDeliveryReportSMSImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (RecipientDeliveryReportSMSImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (RecipientDeliveryReportSMSImpl.class.equals(String.class) + && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = + tree.traverse(jp.getCodec()).readValueAs(RecipientDeliveryReportSMSImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'RecipientDeliveryReportSMSImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log( + Level.FINER, "Input data does not match schema 'RecipientDeliveryReportSMSImpl'", e); + } + + // deserialize TextMessageImpl + try { + boolean attemptParsing = true; + // ensure that we respect type coercion as set on the client ObjectMapper + if (TextMessageImpl.class.equals(Integer.class) + || TextMessageImpl.class.equals(Long.class) + || TextMessageImpl.class.equals(Float.class) + || TextMessageImpl.class.equals(Double.class) + || TextMessageImpl.class.equals(Boolean.class) + || TextMessageImpl.class.equals(String.class)) { + attemptParsing = typeCoercion; + if (!attemptParsing) { + attemptParsing |= + ((TextMessageImpl.class.equals(Integer.class) + || TextMessageImpl.class.equals(Long.class)) + && token == JsonToken.VALUE_NUMBER_INT); + attemptParsing |= + ((TextMessageImpl.class.equals(Float.class) + || TextMessageImpl.class.equals(Double.class)) + && token == JsonToken.VALUE_NUMBER_FLOAT); + attemptParsing |= + (TextMessageImpl.class.equals(Boolean.class) + && (token == JsonToken.VALUE_FALSE || token == JsonToken.VALUE_TRUE)); + attemptParsing |= + (TextMessageImpl.class.equals(String.class) && token == JsonToken.VALUE_STRING); + } + } + if (attemptParsing) { + deserialized = tree.traverse(jp.getCodec()).readValueAs(TextMessageImpl.class); + // TODO: there is no validation against JSON schema constraints + // (min, max, enum, pattern...), this does not perform a strict JSON + // validation, which means the 'match' count may be higher than it should be. + match++; + log.log(Level.FINER, "Input data matches schema 'TextMessageImpl'"); + } + } catch (Exception e) { + // deserialization failed, continue + log.log(Level.FINER, "Input data does not match schema 'TextMessageImpl'", e); + } + + if (match == 1) { + WebhookEventOneOfImpl ret = new WebhookEventOneOfImpl(); + ret.setActualInstance(deserialized); + return ret; + } + throw new IOException( + String.format( + "Failed deserialization for WebhookEventOneOfImpl: %d classes match result, expected" + + " 1", + match)); + } + + /** Handle deserialization of the 'null' value. */ + @Override + public WebhookEventOneOfImpl getNullValue(DeserializationContext ctxt) + throws JsonMappingException { + throw new JsonMappingException(ctxt.getParser(), "WebhookEventOneOfImpl cannot be null"); + } + } + + // store a list of schema names defined in oneOf + public static final Map> schemas = new HashMap<>(); + + public WebhookEventOneOfImpl() { + super("oneOf", Boolean.FALSE); + } + + public WebhookEventOneOfImpl(BatchDeliveryReportMMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public WebhookEventOneOfImpl(BatchDeliveryReportSMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public WebhookEventOneOfImpl(BinaryMessageImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public WebhookEventOneOfImpl(MediaMessageImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public WebhookEventOneOfImpl(RecipientDeliveryReportMMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public WebhookEventOneOfImpl(RecipientDeliveryReportSMSImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + public WebhookEventOneOfImpl(TextMessageImpl o) { + super("oneOf", Boolean.FALSE); + setActualInstance(o); + } + + static { + schemas.put("BatchDeliveryReportMMSImpl", BatchDeliveryReportMMSImpl.class); + schemas.put("BatchDeliveryReportSMSImpl", BatchDeliveryReportSMSImpl.class); + schemas.put("BinaryMessageImpl", BinaryMessageImpl.class); + schemas.put("MediaMessageImpl", MediaMessageImpl.class); + schemas.put("RecipientDeliveryReportMMSImpl", RecipientDeliveryReportMMSImpl.class); + schemas.put("RecipientDeliveryReportSMSImpl", RecipientDeliveryReportSMSImpl.class); + schemas.put("TextMessageImpl", TextMessageImpl.class); + JSONNavigator.registerDescendants( + WebhookEventOneOfImpl.class, Collections.unmodifiableMap(schemas)); + // Initialize and register the discriminator mappings. + Map> mappings = new HashMap>(); + mappings.put("delivery_report_mms", BatchDeliveryReportMMSImpl.class); + mappings.put("delivery_report_sms", BatchDeliveryReportSMSImpl.class); + mappings.put("mo_binary", BinaryMessageImpl.class); + mappings.put("mo_media", MediaMessageImpl.class); + mappings.put("mo_text", TextMessageImpl.class); + mappings.put("recipient_delivery_report_mms", RecipientDeliveryReportMMSImpl.class); + mappings.put("recipient_delivery_report_sms", RecipientDeliveryReportSMSImpl.class); + mappings.put("BatchDeliveryReportMMS", BatchDeliveryReportMMSImpl.class); + mappings.put("BatchDeliveryReportSMS", BatchDeliveryReportSMSImpl.class); + mappings.put("MOBinary", BinaryMessageImpl.class); + mappings.put("MOMedia", MediaMessageImpl.class); + mappings.put("MOText", TextMessageImpl.class); + mappings.put("RecipientDeliveryReportMMS", RecipientDeliveryReportMMSImpl.class); + mappings.put("RecipientDeliveryReportSMS", RecipientDeliveryReportSMSImpl.class); + mappings.put("WebhookEventOneOf", WebhookEventOneOfImpl.class); + JSONNavigator.registerDiscriminator(WebhookEventOneOfImpl.class, "type", mappings); + } + + @Override + public Map> getSchemas() { + return WebhookEventOneOfImpl.schemas; + } + + /** + * Set the instance that matches the oneOf child schema, check the instance parameter is valid + * against the oneOf child schemas: BatchDeliveryReportMMSImpl, BatchDeliveryReportSMSImpl, + * BinaryMessageImpl, MediaMessageImpl, RecipientDeliveryReportMMSImpl, + * RecipientDeliveryReportSMSImpl, TextMessageImpl + * + *

It could be an instance of the 'oneOf' schemas. The oneOf child schemas may themselves be a + * composed schema (allOf, anyOf, oneOf). + */ + @Override + public void setActualInstance(Object instance) { + if (JSONNavigator.isInstanceOf( + BatchDeliveryReportMMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf( + BatchDeliveryReportSMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(BinaryMessageImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(MediaMessageImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf( + RecipientDeliveryReportMMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf( + RecipientDeliveryReportSMSImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + if (JSONNavigator.isInstanceOf(TextMessageImpl.class, instance, new HashSet>())) { + super.setActualInstance(instance); + return; + } + + throw new RuntimeException( + "Invalid instance type. Must be BatchDeliveryReportMMSImpl, BatchDeliveryReportSMSImpl," + + " BinaryMessageImpl, MediaMessageImpl, RecipientDeliveryReportMMSImpl," + + " RecipientDeliveryReportSMSImpl, TextMessageImpl"); + } + + /** + * Get the actual instance, which can be the following: BatchDeliveryReportMMSImpl, + * BatchDeliveryReportSMSImpl, BinaryMessageImpl, MediaMessageImpl, + * RecipientDeliveryReportMMSImpl, RecipientDeliveryReportSMSImpl, TextMessageImpl + * + * @return The actual instance (BatchDeliveryReportMMSImpl, BatchDeliveryReportSMSImpl, + * BinaryMessageImpl, MediaMessageImpl, RecipientDeliveryReportMMSImpl, + * RecipientDeliveryReportSMSImpl, TextMessageImpl) + */ + @Override + public Object getActualInstance() { + return super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchDeliveryReportMMSImpl`. If the actual instance is not + * `BatchDeliveryReportMMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `BatchDeliveryReportMMSImpl` + * @throws ClassCastException if the instance is not `BatchDeliveryReportMMSImpl` + */ + public BatchDeliveryReportMMSImpl getBatchDeliveryReportMMSImpl() throws ClassCastException { + return (BatchDeliveryReportMMSImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `BatchDeliveryReportSMSImpl`. If the actual instance is not + * `BatchDeliveryReportSMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `BatchDeliveryReportSMSImpl` + * @throws ClassCastException if the instance is not `BatchDeliveryReportSMSImpl` + */ + public BatchDeliveryReportSMSImpl getBatchDeliveryReportSMSImpl() throws ClassCastException { + return (BatchDeliveryReportSMSImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `BinaryMessageImpl`. If the actual instance is not + * `BinaryMessageImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `BinaryMessageImpl` + * @throws ClassCastException if the instance is not `BinaryMessageImpl` + */ + public BinaryMessageImpl getBinaryMessageImpl() throws ClassCastException { + return (BinaryMessageImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `MediaMessageImpl`. If the actual instance is not + * `MediaMessageImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `MediaMessageImpl` + * @throws ClassCastException if the instance is not `MediaMessageImpl` + */ + public MediaMessageImpl getMediaMessageImpl() throws ClassCastException { + return (MediaMessageImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `RecipientDeliveryReportMMSImpl`. If the actual instance is not + * `RecipientDeliveryReportMMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `RecipientDeliveryReportMMSImpl` + * @throws ClassCastException if the instance is not `RecipientDeliveryReportMMSImpl` + */ + public RecipientDeliveryReportMMSImpl getRecipientDeliveryReportMMSImpl() + throws ClassCastException { + return (RecipientDeliveryReportMMSImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `RecipientDeliveryReportSMSImpl`. If the actual instance is not + * `RecipientDeliveryReportSMSImpl`, the ClassCastException will be thrown. + * + * @return The actual instance of `RecipientDeliveryReportSMSImpl` + * @throws ClassCastException if the instance is not `RecipientDeliveryReportSMSImpl` + */ + public RecipientDeliveryReportSMSImpl getRecipientDeliveryReportSMSImpl() + throws ClassCastException { + return (RecipientDeliveryReportSMSImpl) super.getActualInstance(); + } + + /** + * Get the actual instance of `TextMessageImpl`. If the actual instance is not `TextMessageImpl`, + * the ClassCastException will be thrown. + * + * @return The actual instance of `TextMessageImpl` + * @throws ClassCastException if the instance is not `TextMessageImpl` + */ + public TextMessageImpl getTextMessageImpl() throws ClassCastException { + return (TextMessageImpl) super.getActualInstance(); + } + + public static class Deserializer + extends StdDeserializer { + + public Deserializer() { + this(null); + } + + public Deserializer(Class vc) { + super(vc); + } + + @Override + public com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent deserialize( + JsonParser jp, DeserializationContext ctxt) throws IOException { + + Object deserialized = jp.readValueAs(WebhookEventOneOfImpl.class).getActualInstance(); + if (null == deserialized) { + return null; + } + if (!(deserialized instanceof com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent)) { + log.log(Level.SEVERE, "Input data does not match schema ", deserialized); + return null; + } + + return (com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent) deserialized; + } + } +} From 23b8b33eb1e35d32cb51bb21b6eae0c64766883c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sun, 12 Jan 2025 10:29:44 +0100 Subject: [PATCH 44/65] refactor (SMS/Webhooks): Fix 'parse' vs 'parseEvent' funtion name --- .../sdk/domains/sms/api/v1/WebHooksService.java | 2 +- .../sms/api/v1/adapters/WebHooksService.java | 2 +- .../sms/api/v1/adapters/WebHooksServiceTest.java | 14 +++++++------- .../sdk/e2e/domains/sms/v1/WebhooksSteps.java | 9 +++++---- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java index 72fab711c..200922acf 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java @@ -5,5 +5,5 @@ public interface WebHooksService { - SmsEvent parse(String jsonPayload) throws ApiMappingException; + SmsEvent parseEvent(String jsonPayload) throws ApiMappingException; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java index 2820c2233..3993979ea 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java @@ -7,7 +7,7 @@ public class WebHooksService implements com.sinch.sdk.domains.sms.api.v1.WebHooksService { - public SmsEvent parse(String jsonPayload) throws ApiMappingException { + public SmsEvent parseEvent(String jsonPayload) throws ApiMappingException { try { return Mapper.getInstance().readValue(jsonPayload, SmsEvent.class); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java index 63c50a31f..d96ba4e27 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java @@ -41,7 +41,7 @@ public class WebHooksServiceTest extends BaseTest { @Test void incomingSMSBinary() throws ApiException { - SmsEvent response = service.parse(loadedInboundBinaryEvent); + SmsEvent response = service.parseEvent(loadedInboundBinaryEvent); TestHelpers.recursiveEquals(InboundMessageDtoTest.binaryDTO, response); } @@ -49,7 +49,7 @@ void incomingSMSBinary() throws ApiException { @Test void incomingSMSText() throws ApiException { - SmsEvent response = service.parse(loadedInboundTextEvent); + SmsEvent response = service.parseEvent(loadedInboundTextEvent); TestHelpers.recursiveEquals(InboundMessageDtoTest.textDTO, response); } @@ -57,7 +57,7 @@ void incomingSMSText() throws ApiException { @Test void incomingSMSMedia() throws ApiException { - SmsEvent response = service.parse(loadedInboundMediaEvent); + SmsEvent response = service.parseEvent(loadedInboundMediaEvent); TestHelpers.recursiveEquals(InboundMessageDtoTest.mediaDTO, response); } @@ -65,7 +65,7 @@ void incomingSMSMedia() throws ApiException { @Test void deliveryReportRecipientDeliveryReportSms() throws ApiException { - SmsEvent response = service.parse(loadedRecipientDeliveryReportSMSEvent); + SmsEvent response = service.parseEvent(loadedRecipientDeliveryReportSMSEvent); TestHelpers.recursiveEquals( RecipientDeliveryReportDtoTest.deliveryReportRecipientSMS, response); @@ -74,7 +74,7 @@ void deliveryReportRecipientDeliveryReportSms() throws ApiException { @Test void deliveryReportRecipientDeliveryReportMms() throws ApiException { - SmsEvent response = service.parse(loadedRecipientDeliveryReportMMSEvent); + SmsEvent response = service.parseEvent(loadedRecipientDeliveryReportMMSEvent); TestHelpers.recursiveEquals( RecipientDeliveryReportDtoTest.deliveryReportRecipientMMS, response); @@ -83,7 +83,7 @@ void deliveryReportRecipientDeliveryReportMms() throws ApiException { @Test void deliveryReportBatchDeliveryReportSms() throws ApiException { - SmsEvent response = service.parse(loadedBatchDeliveryReportSMSEvent); + SmsEvent response = service.parseEvent(loadedBatchDeliveryReportSMSEvent); TestHelpers.recursiveEquals(BatchDeliveryReportDtoTest.deliveryReportBatchSMS, response); } @@ -91,7 +91,7 @@ void deliveryReportBatchDeliveryReportSms() throws ApiException { @Test void deliveryReportBatchDeliveryReportMms() throws ApiException { - SmsEvent response = service.parse(loadedBatchDeliveryReportMMSEvent); + SmsEvent response = service.parseEvent(loadedBatchDeliveryReportMMSEvent); TestHelpers.recursiveEquals(BatchDeliveryReportDtoTest.deliveryReportBatchMMS, response); } diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java index 23a0d9475..be7ca72f0 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java @@ -40,14 +40,14 @@ public void serviceAvailable() { @When("^I send a request to trigger an \"incoming SMS\" event") public void incoming() throws IOException { - incoming = WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/incoming-sms"), service::parse); + incoming = WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/incoming-sms"), service::parseEvent); } @When("^I send a request to trigger an \"SMS delivery report\" event") public void deliveryReport() throws IOException { deliveryReport = - WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/delivery-report-sms"), service::parse); + WebhooksHelper.callURL(new URL(WEBHOOKS_URL + "/delivery-report-sms"), service::parseEvent); } @When( @@ -57,7 +57,8 @@ public void deliveryReportRecipientDelivered() throws IOException { deliveryReportRecipientDelivered = WebhooksHelper.callURL( - new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-delivered"), service::parse); + new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-delivered"), + service::parseEvent); } @When( @@ -67,7 +68,7 @@ public void deliveryReportRecipientAborted() throws IOException { deliveryReportRecipientAborted = WebhooksHelper.callURL( - new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-aborted"), service::parse); + new URL(WEBHOOKS_URL + "/recipient-delivery-report-sms-aborted"), service::parseEvent); } @Then("the SMS event describes an \"incoming SMS\" event") From 7898711fe3b11d35e1395ee772df1f6b2c4a3baa Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 7 Jan 2025 15:53:16 +0100 Subject: [PATCH 45/65] test (SMS/Groups): Refactor V0 test resources --- .../sinch/sdk/domains/sms/adapters/GroupsServiceTest.java | 8 ++++---- .../sms/adapters/converters/GroupsDtoConverterTest.java | 8 ++++---- .../domains/sms/models/dto/v1/GroupResponseDtoTest.java | 5 +++-- ...questParametersDto.json => CreateGroupRequestDto.json} | 0 ...uestParametersDto.json => ReplaceGroupRequestDto.json} | 0 .../v1/{GroupResponseDto.json => groups/GroupDto.json} | 3 ++- .../request/GroupUpdateRequestDto.json} | 0 .../response/ListGroupsResponseDtoPage0.json} | 0 .../response/ListGroupsResponseDtoPage1.json} | 0 .../response/ListGroupsResponseDtoPage2.json} | 0 10 files changed, 13 insertions(+), 11 deletions(-) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupCreateRequestParametersDto.json => CreateGroupRequestDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupReplaceRequestParametersDto.json => ReplaceGroupRequestDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupResponseDto.json => groups/GroupDto.json} (84%) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupUpdateRequestParametersDto.json => groups/request/GroupUpdateRequestDto.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupsListResponseDtoPage0.json => groups/response/ListGroupsResponseDtoPage0.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupsListResponseDtoPage1.json => groups/response/ListGroupsResponseDtoPage1.json} (100%) rename openapi-contracts/src/test/resources/domains/sms/v1/{GroupsListResponseDtoPage2.json => groups/response/ListGroupsResponseDtoPage2.json} (100%) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java index 9bc1bfe99..2d0baae11 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java @@ -51,16 +51,16 @@ class GroupsServiceTest extends BaseTest { @Captor ArgumentCaptor groupIdCaptor; - @GivenJsonResource("/domains/sms/v1/GroupResponseDto.json") + @GivenJsonResource("/domains/sms/v1/groups/GroupDto.json") CreateGroupResponseDto createGroupResponseDto; - @GivenJsonResource("/domains/sms/v1/GroupsListResponseDtoPage0.json") + @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json") ApiGroupListDto groupsListResponseDtoPage0; - @GivenJsonResource("/domains/sms/v1/GroupsListResponseDtoPage1.json") + @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json") ApiGroupListDto groupsListResponseDtoPage1; - @GivenJsonResource("/domains/sms/v1/GroupsListResponseDtoPage2.json") + @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage2.json") ApiGroupListDto groupsListResponseDtoPage2; @BeforeEach diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java index dba3a52ee..4341d225d 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java @@ -27,16 +27,16 @@ @TestWithResources class GroupsDtoConverterTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/GroupResponseDto.json") + @GivenJsonResource("/domains/sms/v1/groups/GroupDto.json") CreateGroupResponseDto createGroupResponseDto; - @GivenJsonResource("/domains/sms/v1/GroupCreateRequestParametersDto.json") + @GivenJsonResource("/domains/sms/v1/CreateGroupRequestDto.json") GroupObjectDto createGroupRequestParametersDto; - @GivenJsonResource("/domains/sms/v1/GroupUpdateRequestParametersDto.json") + @GivenJsonResource("/domains/sms/v1/groups/request/GroupUpdateRequestDto.json") UpdateGroupRequestDto groupUpdateRequestParametersDto; - @GivenJsonResource("/domains/sms/v1/GroupReplaceRequestParametersDto.json") + @GivenJsonResource("/domains/sms/v1/ReplaceGroupRequestDto.json") ReplaceGroupRequestDto groupReplaceRequestParametersDto; static void compareWithDto(Group client, CreateGroupResponseDto dto) { diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java index a5dcb61d8..8cec9ff82 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java @@ -12,7 +12,7 @@ @TestWithResources class GroupResponseDtoTest extends BaseTest { - @GivenJsonResource("/domains/sms/v1/GroupResponseDto.json") + @GivenJsonResource("/domains/sms/v1/groups/GroupDto.json") CreateGroupResponseDto createGroupResponseDto; Integer size = 2; @@ -28,7 +28,8 @@ class GroupResponseDtoTest extends BaseTest { .autoUpdate( new GroupAutoUpdateDto() .to("15551231234") - .add(new AddKeywordDto().firstWord("Add 1st keyword")) + .add(new AddKeywordDto().firstWord("Add 1st keyword") + .secondWord("Add 2nd keyword")) .remove( new RemoveKeywordDto() .firstWord("remove 1st keyword") diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupCreateRequestParametersDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/CreateGroupRequestDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupCreateRequestParametersDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/CreateGroupRequestDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupReplaceRequestParametersDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/ReplaceGroupRequestDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupReplaceRequestParametersDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/ReplaceGroupRequestDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupResponseDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/GroupDto.json similarity index 84% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupResponseDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/groups/GroupDto.json index ffa0a0ea1..34561e6fb 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/GroupResponseDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/groups/GroupDto.json @@ -11,7 +11,8 @@ "auto_update": { "to": 15551231234, "add": { - "first_word": "Add 1st keyword" + "first_word": "Add 1st keyword", + "second_word": "Add 2nd keyword" }, "remove":{ "first_word": "remove 1st keyword", diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupUpdateRequestParametersDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupUpdateRequestParametersDto.json rename to openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage0.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage0.json rename to openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage1.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage1.json rename to openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage2.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage2.json similarity index 100% rename from openapi-contracts/src/test/resources/domains/sms/v1/GroupsListResponseDtoPage2.json rename to openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage2.json From c908f7c35e58f136391844f2d94b373f09b2c410 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 13 Jan 2025 16:06:40 +0100 Subject: [PATCH 46/65] feat (SMS/Groups): 'Groups' API --- .../sdk/domains/sms/api/v1/GroupsService.java | 126 ++++++++++ .../sdk/domains/sms/api/v1/SMSService.java | 2 + .../sms/api/v1/adapters/GroupsService.java | 76 ++++++ .../sms/api/v1/adapters/SMSService.java | 9 + .../groups/response/ListGroupsResponse.java | 56 +++++ .../converters/GroupsDtoConverterTest.java | 1 + .../api/v1/adapters/GroupsServiceTest.java | 216 +++++++++++++++++ .../sdk/e2e/domains/sms/v1/GroupsSteps.java | 224 ++++++++++++++++++ .../sinch/sdk/e2e/domains/sms/v1/SmsIT.java | 5 +- .../models/dto/v1/GroupResponseDtoTest.java | 6 +- .../sms/models/v1/groups/GroupDtoTest.java | 49 ++++ .../groups/request/GroupRequestDtoTest.java | 52 ++++ .../request/GroupUpdateRequestDtoTest.java | 35 +++ .../v1/groups/request/GroupRequestDto.json | 19 ++ .../groups/request/GroupUpdateRequestDto.json | 5 +- .../com/sinch/sample/BaseApplication.java | 4 + .../sinch/sample/sms/groups/ListMembers.java | 6 +- .../sinch/sample/sms/v1/groups/Create.java | 34 +++ .../sinch/sample/sms/v1/groups/Delete.java | 33 +++ .../com/sinch/sample/sms/v1/groups/Get.java | 33 +++ .../com/sinch/sample/sms/v1/groups/List.java | 34 +++ .../sample/sms/v1/groups/ListMembers.java | 34 +++ .../sinch/sample/sms/v1/groups/Replace.java | 43 ++++ .../sinch/sample/sms/v1/groups/Update.java | 37 +++ 24 files changed, 1127 insertions(+), 12 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java create mode 100644 client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/GroupsSteps.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/GroupDtoTest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestDtoTest.java create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java create mode 100644 openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupRequestDto.json create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Create.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Delete.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Get.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/List.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/ListMembers.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Replace.java create mode 100644 sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Update.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java new file mode 100644 index 000000000..5733cd916 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java @@ -0,0 +1,126 @@ +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; +import java.util.Collection; + +/** + * Groups Service + * + *

A group is a set of phone numbers (or MSISDNs) that can be used as a target when sending an + * SMS. An phone number (MSISDN) can only occur once in a group and any attempts to add a duplicate + * are ignored but not rejected. + * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups + * @since 1.0 + */ +public interface GroupsService { + + /** + * Retrieve a group. + * + *

This operation retrieves a specific group with the provided group ID. + * + * @param groupId The inbound ID found when listing inbound messages + * @return Group associated to groupId + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/RetrieveGroup + * @since 1.0 + */ + Group get(String groupId) throws ApiException; + + /** + * Create a group. + * + *

A group is a set of phone numbers (MSISDNs) that can be used as a target in the + * send_batch_msg operation. An MSISDN can only occur once in a group and any attempts to + * add a duplicate would be ignored but not rejected. + * + * @param parameters Parameters to be used to define group onto creation + * @return Created group + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/CreateGroup + * @since 1.0 + */ + Group create(GroupRequest parameters) throws ApiException; + + /** + * Replace a group + * + *

The replace operation will replace all parameters, including members, of an existing group + * with new values. + * + *

Replacing a group targeted by a batch message scheduled in the future is allowed and changes + * will be reflected when the batch is sent. + * + * @param groupId ID of a group that you are interested in getting. + * @param parameters Parameters to be replaced for group + * @return Group associated to groupId + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ReplaceGroup + * @since 1.0 + */ + Group replace(String groupId, GroupRequest parameters) throws ApiException; + + /** + * Update a group + * + * @param groupId ID of a group that you are interested in getting. + * @param parameters Parameters to be used to update group + * @return Modified group associated to groupId + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/UpdateGroup + * @since 1.0 + */ + Group update(String groupId, GroupUpdateRequest parameters) throws ApiException; + + /** + * Delete a group + * + * @param groupId ID of a group that you are interested in getting. + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup + * @since 1.0 + */ + void delete(String groupId) throws ApiException; + + /** + * Get phone numbers for a group + * + * @param groupId ID of a group that you are interested in getting. + * @return A list of phone numbers in E.164 format. + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup + * @since 1.0 + */ + Collection listMembers(String groupId) throws ApiException; + + /** + * List Groups + * + *

With the list operation you can list all groups that you have created. This operation + * supports pagination. + * + *

Groups are returned in reverse chronological order. + * + * @param parameters Filtering parameters + * @return group list + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ListGroups + * @since 1.0 + */ + ListGroupsResponse list(ListGroupsQueryParameters parameters) throws ApiException; + + /** + * List groups with default parameters + * + * @return See {@link #list(ListGroupsQueryParameters)} + * @since 1.0 + */ + ListGroupsResponse list() throws ApiException; +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java index 69a153d23..cec2c4e42 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -8,5 +8,7 @@ public interface SMSService { DeliveryReportsService deliveryReports(); + GroupsService groups(); + WebHooksService webhooks(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java new file mode 100644 index 000000000..72a78b9c5 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java @@ -0,0 +1,76 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.internal.GroupsApi; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; +import com.sinch.sdk.domains.sms.models.v1.groups.response.internal.ApiGroupList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; +import com.sinch.sdk.models.SmsContext; +import java.util.Collection; +import java.util.Map; + +public class GroupsService implements com.sinch.sdk.domains.sms.api.v1.GroupsService { + + private final GroupsApi api; + + protected GroupsApi getApi() { + return this.api; + } + + public GroupsService( + String uriUUID, + SmsContext context, + HttpClient httpClient, + Map authManagers) { + this.api = + new GroupsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); + } + + public Group get(String groupId) throws ApiException { + + return getApi().retrieveGroup(groupId); + } + + public Group create(GroupRequest parameters) throws ApiException { + + return getApi().createGroup(parameters); + } + + public Group replace(String groupId, GroupRequest parameters) throws ApiException { + + return getApi().replaceGroup(groupId, parameters); + } + + public Group update(String groupId, GroupUpdateRequest parameters) throws ApiException { + return getApi().updateGroup(groupId, parameters); + } + + public void delete(String groupId) throws ApiException { + getApi().deleteGroup(groupId); + } + + public Collection listMembers(String groupId) throws ApiException { + return getApi().getMembers(groupId); + } + + public ListGroupsResponse list(ListGroupsQueryParameters parameters) throws ApiException { + ApiGroupList response = getApi().listGroups(parameters); + + SMSCursorPageNavigator navigator = + new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); + + return new ListGroupsResponse(this, new Page<>(parameters, response.getGroups(), navigator)); + } + + public ListGroupsResponse list() throws ApiException { + return list(null); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index d6f08f978..a7ef25f50 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -30,6 +30,7 @@ public class SMSService implements com.sinch.sdk.domains.sms.api.v1.SMSService { private BatchesService batches; private InboundsService inbounds; private DeliveryReportsService deliveryReports; + private GroupsService groups; private WebHooksService webhooks; public SMSService( @@ -106,6 +107,14 @@ public DeliveryReportsService deliveryReports() { return this.deliveryReports; } + @Override + public GroupsService groups() { + if (null == this.groups) { + this.groups = new GroupsService(uriUUID, context, httpClient, authManagers); + } + return this.groups; + } + @Override public WebHooksService webhooks() { if (null == this.webhooks) { diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java new file mode 100644 index 000000000..3a32691c5 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java @@ -0,0 +1,56 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.response; + +import com.sinch.sdk.core.models.pagination.ListResponse; +import com.sinch.sdk.core.models.pagination.Page; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import java.util.Collection; +import java.util.NoSuchElementException; + +public class ListGroupsResponse extends ListResponse { + + private final Page page; + private final GroupsService service; + private ListGroupsResponse nextPage; + + public ListGroupsResponse( + GroupsService service, Page page) { + this.service = service; + this.page = page; + } + + public boolean hasNextPage() { + + if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { + return false; + } + if (null == nextPage) { + ListGroupsQueryParameters.Builder newParameters = + ListGroupsQueryParameters.builder(page.getParameters()); + newParameters.setPage(page.getNextPageToken()); + nextPage = service.list(newParameters.build()); + } + return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); + } + + public ListGroupsResponse nextPage() { + + if (!hasNextPage()) { + throw new NoSuchElementException("Reached the last page of the API response"); + } + + ListGroupsResponse response = nextPage; + nextPage = null; + return response; + } + + public Collection getContent() { + return page.getEntities(); + } + + @Override + public String toString() { + return "ListGroupsResponse {" + "page=" + page + '}'; + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java index 4341d225d..3448fd607 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java @@ -115,6 +115,7 @@ void convertUpdateRequestParameters() throws UnexpectedException { .setAdd( GroupAutoUpdateKeywordRequestParameters.builder() .setFirstWord("Add 1st keyword") + .setSecondWord("Add 2nd keyword") .build()) .setRemove( GroupAutoUpdateKeywordRequestParameters.builder() diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java new file mode 100644 index 000000000..a24bec812 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java @@ -0,0 +1,216 @@ +package com.sinch.sdk.domains.sms.api.v1.adapters; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.domains.sms.api.v1.internal.GroupsApi; +import com.sinch.sdk.domains.sms.models.v1.groups.AddKeyword; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; +import com.sinch.sdk.domains.sms.models.v1.groups.RemoveKeyword; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; +import com.sinch.sdk.domains.sms.models.v1.groups.response.internal.ApiGroupList; +import com.sinch.sdk.models.SmsContext; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; +import org.mockito.Captor; +import org.mockito.Mock; + +@TestWithResources +class GroupsServiceTest extends BaseTest { + + @Mock SmsContext context; + @Mock HttpClient httpClient; + @Mock Map authManagers; + @Mock GroupsApi api; + GroupsService service; + String uriPartID = "foovalue"; + + @Captor ArgumentCaptor groupIdCaptor; + + @GivenJsonResource("/domains/sms/v1/groups/GroupDto.json") + Group groupResponseDto; + + @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json") + ApiGroupList groupsListResponseDtoPage0; + + @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json") + ApiGroupList groupsListResponseDtoPage1; + + @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage2.json") + ApiGroupList groupsListResponseDtoPage2; + + @BeforeEach + public void initMocks() { + service = spy(new GroupsService(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @Test + void get() throws ApiException { + + when(api.retrieveGroup(eq("foo group ID"))).thenReturn(groupResponseDto); + + Group response = service.get("foo group ID"); + + TestHelpers.recursiveEquals(response, groupResponseDto); + } + + @Test + void create() throws ApiException { + + when(api.createGroup(eq(null))).thenReturn(groupResponseDto); + + Group response = service.create(null); + + TestHelpers.recursiveEquals(response, groupResponseDto); + } + + @Test + void list() throws ApiException { + + ListGroupsQueryParameters page1 = ListGroupsQueryParameters.builder().setPage(1).build(); + ListGroupsQueryParameters page2 = ListGroupsQueryParameters.builder().setPage(2).build(); + + when(api.listGroups(eq(null))).thenReturn(groupsListResponseDtoPage0); + when(api.listGroups(page1)).thenReturn(groupsListResponseDtoPage1); + when(api.listGroups(page2)).thenReturn(groupsListResponseDtoPage2); + + ListGroupsResponse response = service.list(null); + + Iterator iterator = response.iterator(); + Group item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + + TestHelpers.recursiveEquals( + item, + Group.builder() + .setId("01FC66621XXXXX119Z8PMV1QPU") + .setName("My new customers") + .setSize(2) + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd(AddKeyword.builder().setFirstWord("Add 1st keyword").build()) + .setRemove( + RemoveKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .setChildGroups( + new HashSet<>( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) + .build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TestHelpers.recursiveEquals(item, Group.builder().setId("foo id").build()); + + item = iterator.next(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + TestHelpers.recursiveEquals( + item, + Group.builder() + .setId("01FC66621XXXXX119Z8PMV1QPU") + .setName("My new customers") + .setSize(2) + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd(AddKeyword.builder().setFirstWord("Add 1st keyword").build()) + .setRemove( + RemoveKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .setChildGroups( + new HashSet<>( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) + .build()); + } + + @Test + void replace() throws ApiException { + + when(api.replaceGroup( + eq("group id"), + eq( + GroupRequest.builder() + .setName("foo name") + .setMembers(Collections.singleton("foo member")) + .build()))) + .thenReturn(groupResponseDto); + + Group response = + service.replace( + "group id", + GroupRequest.builder() + .setName("foo name") + .setMembers(Collections.singleton("foo member")) + .build()); + + TestHelpers.recursiveEquals(response, groupResponseDto); + } + + @Test + void update() throws ApiException { + + when(api.updateGroup( + eq("group id"), eq(GroupUpdateRequest.builder().setName("foo name").build()))) + .thenReturn(groupResponseDto); + + Group response = + service.update("group id", GroupUpdateRequest.builder().setName("foo name").build()); + + TestHelpers.recursiveEquals(response, groupResponseDto); + } + + @Test + void delete() throws ApiException { + + service.delete("foo group id"); + + verify(api).deleteGroup(groupIdCaptor.capture()); + + String parameter = groupIdCaptor.getValue(); + Assertions.assertThat(parameter).isEqualTo("foo group id"); + } + + @Test + void listMembers() throws ApiException { + + when(api.getMembers(eq("group id"))).thenReturn(Arrays.asList("entry 1", "entry 2")); + + Collection response = service.listMembers("group id"); + + TestHelpers.recursiveEquals(response, Arrays.asList("entry 1", "entry 2")); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/GroupsSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/GroupsSteps.java new file mode 100644 index 000000000..2c303a00b --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/GroupsSteps.java @@ -0,0 +1,224 @@ +package com.sinch.sdk.e2e.domains.sms.v1; + +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; +import com.sinch.sdk.e2e.Config; +import io.cucumber.java.en.Given; +import io.cucumber.java.en.Then; +import io.cucumber.java.en.When; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.concurrent.atomic.AtomicInteger; +import org.junit.jupiter.api.Assertions; + +public class GroupsSteps { + + GroupsService service; + Group createResponse; + Group getResponse; + ListGroupsResponse listOnePageResponse; + ListGroupsResponse listAllResponse; + ListGroupsResponse listAllByPageResponse; + Group updateResponse; + Group updateRemoveNameResponse; + Group replaceResponse; + Boolean deletePassed; + Collection lisMembersResponse; + + @Given("^the SMS service \"Groups\" is available") + public void serviceAvailable() { + + service = Config.getSinchClient().sms().v1().groups(); + } + + @When("^I send a request to create an SMS group$") + public void create() { + GroupRequest request = + GroupRequest.builder() + .setName("Group master") + .setMembers(new HashSet<>(Arrays.asList("+12017778888", "+12018887777"))) + .setChildGroups(new HashSet<>(Arrays.asList("01W4FFL35P4NC4K35SUBGROUP1"))) + .build(); + + createResponse = service.create(request); + } + + @When("^I send a request to retrieve an SMS group$") + public void get() { + + getResponse = service.get("01W4FFL35P4NC4K35SMSGROUP1"); + } + + @When("^I send a request to list the existing SMS groups$") + public void listOnePage() { + ListGroupsQueryParameters request = ListGroupsQueryParameters.builder().setPageSize(2).build(); + + listOnePageResponse = service.list(request); + } + + @When("^I send a request to list all the SMS groups$") + public void listAll() { + ListGroupsQueryParameters request = ListGroupsQueryParameters.builder().setPageSize(2).build(); + + listAllResponse = service.list(request); + } + + @When("^I iterate manually over the SMS groups pages$") + public void listAllByPage() { + ListGroupsQueryParameters request = ListGroupsQueryParameters.builder().setPageSize(2).build(); + + listAllByPageResponse = service.list(request); + } + + @When("^I send a request to update an SMS group$") + public void update() { + + GroupUpdateRequest parameters = + GroupUpdateRequest.builder() + .setName("Updated group name") + .setAdd(Arrays.asList("+12017771111", "+12017772222")) + .setRemove(Arrays.asList("+12017773333", "+12017774444")) + .setAddFromGroup("01W4FFL35P4NC4K35SMSGROUP2") + .setRemoveFromGroup("01W4FFL35P4NC4K35SMSGROUP3") + .build(); + updateResponse = service.update("groupid", parameters); + } + + @When("^I send a request to update an SMS group to remove its name$") + public void updateRemoveName() { + + GroupUpdateRequest parameters = GroupUpdateRequest.builder().setName(null).build(); + updateRemoveNameResponse = service.update("groupid", parameters); + } + + @When("^I send a request to replace an SMS group$") + public void replace() { + + GroupRequest parameters = + GroupRequest.builder() + .setName("Replacement group") + .setMembers( + new HashSet<>(Arrays.asList("+12018881111", "+12018882222", "+12018883333"))) + .build(); + replaceResponse = service.replace("groupid", parameters); + } + + @When("^I send a request to delete an SMS group$") + public void delete() { + + service.delete("groupid"); + deletePassed = true; + } + + @When("^I send a request to list the members of an SMS group$") + public void listMembers() { + + lisMembersResponse = service.listMembers("groupid"); + } + + @Then("the response contains the SMS group details") + public void createOrGetResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP1") + .setName("Group master") + .setSize(2) + .setCreatedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setModifiedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setChildGroups(new HashSet<>(Collections.singleton("01W4FFL35P4NC4K35SUBGROUP1"))) + .build(); + + Group current = null != createResponse ? createResponse : getResponse; + + TestHelpers.recursiveEquals(current, expected); + } + + @Then("the response contains \"{int}\" SMS groups") + public void onePageResult(int expected) { + + Assertions.assertEquals(listOnePageResponse.getContent().size(), expected); + } + + @Then("the SMS groups list contains \"{int}\" SMS groups") + public void listAllResult(int expected) { + ListGroupsResponse response = null != listAllResponse ? listAllResponse : listAllByPageResponse; + + AtomicInteger count = new AtomicInteger(); + response.iterator().forEachRemaining(_unused -> count.getAndIncrement()); + + Assertions.assertEquals(count.get(), expected); + } + + @Then("the SMS groups iteration result contains the data from \"{int}\" pages") + public void listAllByPageResult(int expected) { + + int count = listAllByPageResponse.getContent().isEmpty() ? 0 : 1; + while (listAllByPageResponse.hasNextPage()) { + count++; + listAllByPageResponse = listAllByPageResponse.nextPage(); + } + Assertions.assertEquals(count, expected); + } + + @Then("the response contains the updated SMS group details") + public void updateResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP1") + .setName("Updated group name") + .setSize(6) + .setCreatedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setModifiedAt(Instant.parse("2024-06-06T09:19:58.147Z")) + .setChildGroups(new HashSet<>(Collections.singleton("01W4FFL35P4NC4K35SUBGROUP1"))) + .build(); + TestHelpers.recursiveEquals(updateResponse, expected); + } + + @Then("the response contains the updated SMS group details where the name has been removed") + public void updateRemoveNameResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP2") + .setSize(5) + .setCreatedAt(Instant.parse("2024-06-06T12:45:18.761Z")) + .setModifiedAt(Instant.parse("2024-06-06T13:12:05.137Z")) + .setChildGroups(new HashSet<>()) + .build(); + TestHelpers.recursiveEquals(updateRemoveNameResponse, expected); + } + + @Then("the response contains the replaced SMS group details") + public void replaceResult() { + Group expected = + Group.builder() + .setId("01W4FFL35P4NC4K35SMSGROUP1") + .setName("Replacement group") + .setSize(3) + .setCreatedAt(Instant.parse("2024-06-06T08:59:22.156Z")) + .setModifiedAt(Instant.parse("2024-08-21T09:39:36.679Z")) + .setChildGroups(new HashSet<>(Collections.singleton("01W4FFL35P4NC4K35SUBGROUP1"))) + .build(); + TestHelpers.recursiveEquals(replaceResponse, expected); + } + + @Then("the delete SMS group response contains no data") + public void deleteResult() { + Assertions.assertTrue(deletePassed); + } + + @Then("the response contains the phone numbers of the SMS group") + public void lisMembersResult() { + Collection expected = + new ArrayList<>(Arrays.asList("12018881111", "12018882222", "12018883333")); + TestHelpers.recursiveEquals(lisMembersResponse, expected); + } +} diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java index 2e8feba32..42139b9be 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/SmsIT.java @@ -11,9 +11,6 @@ @Suite @SuiteDisplayName("SMS V1") @IncludeEngines("cucumber") -@SelectClasspathResource("features/sms/batches.feature") -@SelectClasspathResource("features/sms/inbounds.feature") -@SelectClasspathResource("features/sms/delivery-reports.feature") -@SelectClasspathResource("features/sms/webhooks.feature") +@SelectClasspathResource("features/sms") @ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.sinch.sdk.e2e.domains.sms.v1") public class SmsIT {} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java index 8cec9ff82..84a2f4510 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/dto/v1/GroupResponseDtoTest.java @@ -28,8 +28,10 @@ class GroupResponseDtoTest extends BaseTest { .autoUpdate( new GroupAutoUpdateDto() .to("15551231234") - .add(new AddKeywordDto().firstWord("Add 1st keyword") - .secondWord("Add 2nd keyword")) + .add( + new AddKeywordDto() + .firstWord("Add 1st keyword") + .secondWord("Add 2nd keyword")) .remove( new RemoveKeywordDto() .firstWord("remove 1st keyword") diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/GroupDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/GroupDtoTest.java new file mode 100644 index 000000000..8e6803f17 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/GroupDtoTest.java @@ -0,0 +1,49 @@ +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.core.TestHelpers; +import java.time.Instant; +import java.util.Arrays; +import java.util.HashSet; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class GroupDtoTest extends BaseTest { + + @GivenJsonResource("/domains/sms/v1/groups/GroupDto.json") + Group groupResponseDto; + + public static Group groupResponse = + Group.builder() + .setSize(2) + .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) + .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) + .setId("01FC66621XXXXX119Z8PMV1QPU") + .setName("My new customers") + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd( + AddKeyword.builder() + .setFirstWord("Add 1st keyword") + .setSecondWord("Add 2nd keyword") + .build()) + .setRemove( + RemoveKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .setChildGroups( + new HashSet<>( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) + .build(); + + @Test + void deserializeGroup() { + + TestHelpers.recursiveEquals(groupResponseDto, groupResponse); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestDtoTest.java new file mode 100644 index 000000000..c5c25cf62 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestDtoTest.java @@ -0,0 +1,52 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.v1.groups.AddKeyword; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; +import com.sinch.sdk.domains.sms.models.v1.groups.RemoveKeyword; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class GroupRequestDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/groups/request/GroupRequestDto.json") + String jsonGroupRequestDto; + + @Test + void serialize() throws JsonProcessingException, JSONException { + + GroupRequest requestDTO = + GroupRequest.builder() + .setName("My new customers") + .setAutoUpdate( + GroupAutoUpdate.builder() + .setTo("15551231234") + .setAdd( + AddKeyword.builder() + .setFirstWord("Add 1st keyword") + .setSecondWord("Add 2nd keyword") + .build()) + .setRemove( + RemoveKeyword.builder() + .setFirstWord("remove 1st keyword") + .setSecondWord("remove 2nd keyword") + .build()) + .build()) + .setMembers(Collections.singleton("+15551231234")) + .setChildGroups( + new HashSet<>( + Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) + .build(); + + String serializedString = objectMapper.writeValueAsString(requestDTO); + + JSONAssert.assertEquals(jsonGroupRequestDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java new file mode 100644 index 000000000..ab1fc4d76 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java @@ -0,0 +1,35 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.BaseTest; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupDtoTest; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +class GroupUpdateRequestDtoTest extends BaseTest { + @GivenTextResource("/domains/sms/v1/groups/request/GroupUpdateRequestDto.json") + String jsonGroupUpdateRequestDto; + + @Test + void serialize() throws JsonProcessingException, JSONException { + + GroupUpdateRequest requestDTO = + GroupUpdateRequest.builder() + .setName("My new customers") + .setAdd(Arrays.asList("foo")) + .setRemove(Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) + .setAddFromGroup("add from group string") + .setRemoveFromGroup("remove from group string") + .setAutoUpdate(GroupDtoTest.groupResponse.getAutoUpdate()) + .build(); + + String serializedString = objectMapper.writeValueAsString(requestDTO); + + JSONAssert.assertEquals(jsonGroupUpdateRequestDto, serializedString, true); + } +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupRequestDto.json new file mode 100644 index 000000000..d54362892 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupRequestDto.json @@ -0,0 +1,19 @@ +{ + "name": "My new customers", + "child_groups": [ + "01FC66621XXXXX119Z8PMV1AHY", + "01FC66621XXXXX119Z8PMV1A00" + ], + "auto_update": { + "to": "15551231234", + "add": { + "first_word": "Add 1st keyword", + "second_word": "Add 2nd keyword" + }, + "remove": { + "first_word": "remove 1st keyword", + "second_word": "remove 2nd keyword" + } + }, + "members": [ "+15551231234" ] +} diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json index de0b878be..0a95cab1b 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json @@ -10,9 +10,10 @@ "add_from_group": "add from group string", "remove_from_group": "remove from group string", "auto_update": { - "to": 15551231234, + "to": "15551231234", "add": { - "first_word": "Add 1st keyword" + "first_word": "Add 1st keyword", + "second_word": "Add 2nd keyword" }, "remove": { "first_word": "remove 1st keyword", diff --git a/sample-app/src/main/java/com/sinch/sample/BaseApplication.java b/sample-app/src/main/java/com/sinch/sample/BaseApplication.java index 7d3b8bc15..b285c3332 100644 --- a/sample-app/src/main/java/com/sinch/sample/BaseApplication.java +++ b/sample-app/src/main/java/com/sinch/sample/BaseApplication.java @@ -12,6 +12,8 @@ public abstract class BaseApplication { private static final String BATCH_ID_KEY = "BATCH_ID"; + private static final String SMS_GROUP_ID_KEY = "SMS_GROUP_ID"; + public static final String PHONE_NUMBER_KEY = "PHONE_NUMBER"; private static final String VIRTUAL_PHONE_NUMBER_KEY = "VIRTUAL_PHONE_NUMBER"; public static final String CONFERENCE_ID_KEY = "CONFERENCE_ID"; @@ -38,6 +40,7 @@ public abstract class BaseApplication { protected String phoneNumber; protected String virtualPhoneNumber; protected String batchId; + protected String smsGroupId; protected String conferenceId; protected String callId; protected String verificationId; @@ -70,6 +73,7 @@ protected BaseApplication() throws IOException { virtualPhoneNumber = getConfigValue(VIRTUAL_PHONE_NUMBER_KEY); batchId = getConfigValue(BATCH_ID_KEY); + smsGroupId = getConfigValue(SMS_GROUP_ID_KEY); conferenceId = getConfigValue(CONFERENCE_ID_KEY); callId = getConfigValue(CALL_ID_KEY); diff --git a/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java b/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java index 33b00f2cd..ce50c3d88 100644 --- a/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java +++ b/sample-app/src/main/java/com/sinch/sample/sms/groups/ListMembers.java @@ -22,11 +22,9 @@ public static void main(String[] args) { public void run() { - String groupId = "01HF714PHPH9SQ2BNWSCY2068R"; + LOGGER.info("List members for groupId: " + smsGroupId); - LOGGER.info("List members for groupId: " + groupId); - - Collection response = client.sms().groups().listMembers(groupId); + Collection response = client.sms().groups().listMembers(smsGroupId); response.iterator().forEachRemaining(LOGGER::info); } diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Create.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Create.java new file mode 100644 index 000000000..d3e8f75dc --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Create.java @@ -0,0 +1,34 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import java.io.IOException; +import java.util.logging.Logger; + +public class Create extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Create.class.getName()); + + public Create() throws IOException {} + + public static void main(String[] args) { + try { + new Create().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + LOGGER.info("Creating group"); + + Group response = service.create(GroupRequest.builder().setName("Group name").build()); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Delete.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Delete.java new file mode 100644 index 000000000..f783056a3 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Delete.java @@ -0,0 +1,33 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import java.io.IOException; +import java.util.logging.Logger; + +public class Delete extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Delete.class.getName()); + + public Delete() throws IOException {} + + public static void main(String[] args) { + try { + new Delete().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + LOGGER.info("Deleting group: " + smsGroupId); + + service.delete(smsGroupId); + + LOGGER.info("Done"); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Get.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Get.java new file mode 100644 index 000000000..3c778b2e6 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Get.java @@ -0,0 +1,33 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import java.io.IOException; +import java.util.logging.Logger; + +public class Get extends BaseApplication { + private static final Logger LOGGER = Logger.getLogger(Get.class.getName()); + + public Get() throws IOException {} + + public static void main(String[] args) { + try { + new Get().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + LOGGER.info("Get for: " + smsGroupId); + + Group response = service.get(smsGroupId); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/List.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/List.java new file mode 100644 index 000000000..698e5288b --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/List.java @@ -0,0 +1,34 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; +import java.io.IOException; +import java.util.logging.Logger; + +public class List extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(List.class.getName()); + + public List() throws IOException {} + + public static void main(String[] args) { + try { + new List().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + LOGGER.info("List groups"); + + ListGroupsResponse response = service.list(); + + response.iterator().forEachRemaining(f -> LOGGER.info(f.toString())); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/ListMembers.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/ListMembers.java new file mode 100644 index 000000000..2b858520d --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/ListMembers.java @@ -0,0 +1,34 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import java.io.IOException; +import java.util.Collection; +import java.util.logging.Logger; + +public class ListMembers extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(ListMembers.class.getName()); + + public ListMembers() throws IOException {} + + public static void main(String[] args) { + try { + new ListMembers().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + LOGGER.info("List members for groupId: " + smsGroupId); + + Collection response = service.listMembers(smsGroupId); + + response.iterator().forEachRemaining(LOGGER::info); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Replace.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Replace.java new file mode 100644 index 000000000..454ba6ad3 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Replace.java @@ -0,0 +1,43 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashSet; +import java.util.logging.Logger; + +public class Replace extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Replace.class.getName()); + + public Replace() throws IOException {} + + public static void main(String[] args) { + try { + new Replace().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + GroupRequest parameters = + GroupRequest.builder() + .setName("foo") + .setMembers(new HashSet<>(Arrays.asList("+3312345678", "+3312345679"))) + .build(); + + LOGGER.info("Replace group: " + smsGroupId + " with: " + parameters); + + Group response = service.replace(smsGroupId, parameters); + + LOGGER.info("Response :" + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Update.java b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Update.java new file mode 100644 index 000000000..4de6faeb4 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/sms/v1/groups/Update.java @@ -0,0 +1,37 @@ +package com.sinch.sample.sms.v1.groups; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import java.io.IOException; +import java.util.logging.Logger; + +public class Update extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(Update.class.getName()); + + public Update() throws IOException {} + + public static void main(String[] args) { + try { + new Update().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + GroupsService service = client.sms().v1().groups(); + + GroupUpdateRequest parameters = GroupUpdateRequest.builder().setName("new name").build(); + + LOGGER.info("Update group: " + smsGroupId + " with: " + parameters); + + Group response = service.update(smsGroupId, parameters); + + LOGGER.info("Response: " + response); + } +} From 73e7583c381e6f9d3014c2538b3567fbecac9e6e Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 13 Jan 2025 16:07:01 +0100 Subject: [PATCH 47/65] feat (SMS/Groups): generated sources --- .../sms/api/v1/internal/GroupsApi.java | 603 ++++++++++++++++++ .../sms/models/v1/groups/AddKeyword.java | 71 +++ .../sms/models/v1/groups/AddKeywordImpl.java | 118 ++++ .../domains/sms/models/v1/groups/Group.java | 162 +++++ .../sms/models/v1/groups/GroupAutoUpdate.java | 89 +++ .../models/v1/groups/GroupAutoUpdateImpl.java | 147 +++++ .../sms/models/v1/groups/GroupImpl.java | 253 ++++++++ .../sms/models/v1/groups/RemoveKeyword.java | 71 +++ .../models/v1/groups/RemoveKeywordImpl.java | 118 ++++ .../v1/groups/request/GroupRequest.java | 181 ++++++ .../v1/groups/request/GroupRequestImpl.java | 282 ++++++++ .../v1/groups/request/GroupUpdateRequest.java | 141 ++++ .../request/GroupUpdateRequestImpl.java | 231 +++++++ .../request/ListGroupsQueryParameters.java | 78 +++ .../ListGroupsQueryParametersImpl.java | 93 +++ .../response/internal/ApiGroupList.java | 104 +++ .../response/internal/ApiGroupListImpl.java | 176 +++++ 17 files changed, 2918 insertions(+) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeyword.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeywordImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/Group.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdate.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdateImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeyword.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeywordImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequest.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParameters.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParametersImpl.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java new file mode 100644 index 000000000..4ff46673d --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java @@ -0,0 +1,603 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1.internal; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; +import com.sinch.sdk.core.http.AuthManager; +import com.sinch.sdk.core.http.HttpClient; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.HttpStatus; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameterUtils; +import com.sinch.sdk.core.http.URLPathUtils; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.internal.ApiGroupList; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +public class GroupsApi { + + private static final Logger LOGGER = Logger.getLogger(GroupsApi.class.getName()); + private HttpClient httpClient; + private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; + private HttpMapper mapper; + + private final String servicePlanId; + + public GroupsApi( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper, + String servicePlanId) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + this.servicePlanId = servicePlanId; + } + + /** + * Create a group This endpoint allows you to create a group of recipients. A new group must be + * created with a group name. This is represented by the `name` field which can be up to + * 20 charecters. In addition, there are a number of optional fields: - `members` field + * enables groups to be created with an initial list of contacts - `auto_update` allows + * customers to auto subscribe to a new group. This contains three fields. The `to` + * field contains the group creator's number. (This number **must be provisioned by contacting + * your account manager**.) The `add` and `remove` fields are objects + * containing the keywords that customers need to text to join or leave a group. + * + * @param groupRequest (optional) + * @return Group + * @throws ApiException if fails to make API call + */ + public Group createGroup(GroupRequest groupRequest) throws ApiException { + + LOGGER.finest("[createGroup]" + " " + "groupRequest: " + groupRequest); + + HttpRequest httpRequest = createGroupRequestBuilder(groupRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest createGroupRequestBuilder(GroupRequest groupRequest) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling createGroup"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, groupRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Delete a group This operation deletes the group with the provided group ID. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @throws ApiException if fails to make API call + */ + public void deleteGroup(String groupId) throws ApiException { + + LOGGER.finest("[deleteGroup]" + " " + "groupId: " + groupId); + + HttpRequest httpRequest = deleteGroupRequestBuilder(groupId); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + return; + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest deleteGroupRequestBuilder(String groupId) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling deleteGroup"); + } + // verify the required parameter 'groupId' is set + if (groupId == null) { + throw new ApiException( + 400, "Missing the required parameter 'groupId' when calling deleteGroup"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups/{group_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "group_id" + "\\}", URLPathUtils.encodePathSegment(groupId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList(); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.DELETE, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Get phone numbers for a group This operation retrieves the members of the group with the + * provided group ID. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @return List<String> + * @throws ApiException if fails to make API call + */ + public List getMembers(String groupId) throws ApiException { + + LOGGER.finest("[getMembers]" + " " + "groupId: " + groupId); + + HttpRequest httpRequest = getMembersRequestBuilder(groupId); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference> localVarReturnType = new TypeReference>() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest getMembersRequestBuilder(String groupId) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling getMembers"); + } + // verify the required parameter 'groupId' is set + if (groupId == null) { + throw new ApiException( + 400, "Missing the required parameter 'groupId' when calling getMembers"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups/{group_id}/members" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "group_id" + "\\}", URLPathUtils.encodePathSegment(groupId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * List Groups With the list operation you can list all groups that you have created. This + * operation supports pagination. Groups are returned in reverse chronological order. + * + * @return ApiGroupList + * @throws ApiException if fails to make API call + */ + public ApiGroupList listGroups() throws ApiException { + + return listGroups(null); + } + + /** + * List Groups With the list operation you can list all groups that you have created. This + * operation supports pagination. Groups are returned in reverse chronological order. + * + * @param queryParameter (optional) + * @return ApiGroupList + * @throws ApiException if fails to make API call + */ + public ApiGroupList listGroups(ListGroupsQueryParameters queryParameter) throws ApiException { + + LOGGER.finest("[listGroups]" + " " + "queryParameter: " + queryParameter); + + HttpRequest httpRequest = listGroupsRequestBuilder(queryParameter); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest listGroupsRequestBuilder(ListGroupsQueryParameters queryParameter) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling listGroups"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != queryParameter) { + + URLParameterUtils.addQueryParam( + queryParameter.getPage(), "page", URLParameter.form, null, localVarQueryParams, true); + + URLParameterUtils.addQueryParam( + queryParameter.getPageSize(), + "page_size", + URLParameter.form, + null, + localVarQueryParams, + true); + } + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Replace a group The replace operation will replace all parameters, including members, of an + * existing group with new values. Replacing a group targeted by a batch message scheduled in the + * future is allowed and changes will be reflected when the batch is sent. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @param groupRequest (optional) + * @return Group + * @throws ApiException if fails to make API call + */ + public Group replaceGroup(String groupId, GroupRequest groupRequest) throws ApiException { + + LOGGER.finest( + "[replaceGroup]" + " " + "groupId: " + groupId + ", " + "groupRequest: " + groupRequest); + + HttpRequest httpRequest = replaceGroupRequestBuilder(groupId, groupRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest replaceGroupRequestBuilder(String groupId, GroupRequest groupRequest) + throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling replaceGroup"); + } + // verify the required parameter 'groupId' is set + if (groupId == null) { + throw new ApiException( + 400, "Missing the required parameter 'groupId' when calling replaceGroup"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups/{group_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "group_id" + "\\}", URLPathUtils.encodePathSegment(groupId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, groupRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.PUT, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Retrieve a group This operation retrieves a specific group with the provided group ID. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @return Group + * @throws ApiException if fails to make API call + */ + public Group retrieveGroup(String groupId) throws ApiException { + + LOGGER.finest("[retrieveGroup]" + " " + "groupId: " + groupId); + + HttpRequest httpRequest = retrieveGroupRequestBuilder(groupId); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest retrieveGroupRequestBuilder(String groupId) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling retrieveGroup"); + } + // verify the required parameter 'groupId' is set + if (groupId == null) { + throw new ApiException( + 400, "Missing the required parameter 'groupId' when calling retrieveGroup"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups/{group_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "group_id" + "\\}", URLPathUtils.encodePathSegment(groupId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList(); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Update a group With the update group operation, you can add and remove members in an existing + * group as well as rename the group. This method encompasses a few ways to update a group: 1. By + * using `add` and `remove` arrays containing phone numbers, you control the + * group movements. Any list of valid numbers in E.164 format can be added. 2. By using the + * `auto_update` object, your customer can add or remove themselves from groups. 3. You + * can also add or remove other groups into this group with `add_from_group` and + * `remove_from_group`. #### Other group update info - The request will not be rejected + * for duplicate adds or unknown removes. - The additions will be done before the deletions. If an + * phone number is on both lists, it will not be apart of the resulting group. - Updating a group + * targeted by a batch message scheduled in the future is allowed. Changes will be reflected when + * the batch is sent. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @param groupUpdateRequest (optional) + * @return Group + * @throws ApiException if fails to make API call + */ + public Group updateGroup(String groupId, GroupUpdateRequest groupUpdateRequest) + throws ApiException { + + LOGGER.finest( + "[updateGroup]" + + " " + + "groupId: " + + groupId + + ", " + + "groupUpdateRequest: " + + groupUpdateRequest); + + HttpRequest httpRequest = updateGroupRequestBuilder(groupId, groupUpdateRequest); + HttpResponse response = + httpClient.invokeAPI( + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); + + if (HttpStatus.isSuccessfulStatus(response.getCode())) { + TypeReference localVarReturnType = new TypeReference() {}; + return mapper.deserialize(response, localVarReturnType); + } + // fallback to default errors handling: + // all error cases definition are not required from specs: will try some "hardcoded" content + // parsing + throw ApiExceptionBuilder.build( + response.getMessage(), + response.getCode(), + mapper.deserialize(response, new TypeReference>() {})); + } + + private HttpRequest updateGroupRequestBuilder( + String groupId, GroupUpdateRequest groupUpdateRequest) throws ApiException { + // verify the required parameter 'this.servicePlanId' is set + if (this.servicePlanId == null) { + throw new ApiException( + 400, "Missing the required parameter 'this.servicePlanId' when calling updateGroup"); + } + // verify the required parameter 'groupId' is set + if (groupId == null) { + throw new ApiException( + 400, "Missing the required parameter 'groupId' when calling updateGroup"); + } + + String localVarPath = + "/xms/v1/{service_plan_id}/groups/{group_id}" + .replaceAll( + "\\{" + "service_plan_id" + "\\}", + URLPathUtils.encodePathSegment(this.servicePlanId.toString())) + .replaceAll( + "\\{" + "group_id" + "\\}", URLPathUtils.encodePathSegment(groupId.toString())); + + List localVarQueryParams = new ArrayList<>(); + + Map localVarHeaderParams = new HashMap<>(); + + final Collection localVarAccepts = Arrays.asList("application/json"); + + final Collection localVarContentTypes = Arrays.asList("application/json"); + + final Collection localVarAuthNames = Arrays.asList("BearerAuth"); + final String serializedBody = mapper.serialize(localVarContentTypes, groupUpdateRequest); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeyword.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeyword.java new file mode 100644 index 000000000..afaf45826 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeyword.java @@ -0,0 +1,71 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** Keyword to be sent in MO to add MSISDN to a group */ +@JsonDeserialize(builder = AddKeywordImpl.Builder.class) +public interface AddKeyword { + + /** + * Opt-in keyword like "JOIN" if auto_update.to is dedicated long/short number + * or unique brand keyword like "Sinch" if it is a shared short code. + * + * @return firstWord + */ + String getFirstWord(); + + /** + * Opt-in keyword like "JOIN" if auto_update.to is shared short code. + * + * @return secondWord + */ + String getSecondWord(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new AddKeywordImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param firstWord see getter + * @return Current builder + * @see #getFirstWord + */ + Builder setFirstWord(String firstWord); + + /** + * see getter + * + * @param secondWord see getter + * @return Current builder + * @see #getSecondWord + */ + Builder setSecondWord(String secondWord); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + AddKeyword build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeywordImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeywordImpl.java new file mode 100644 index 000000000..91d6fd001 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/AddKeywordImpl.java @@ -0,0 +1,118 @@ +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +@JsonPropertyOrder({ + AddKeywordImpl.JSON_PROPERTY_FIRST_WORD, + AddKeywordImpl.JSON_PROPERTY_SECOND_WORD +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class AddKeywordImpl implements AddKeyword { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_FIRST_WORD = "first_word"; + + private OptionalValue firstWord; + + public static final String JSON_PROPERTY_SECOND_WORD = "second_word"; + + private OptionalValue secondWord; + + public AddKeywordImpl() {} + + protected AddKeywordImpl(OptionalValue firstWord, OptionalValue secondWord) { + this.firstWord = firstWord; + this.secondWord = secondWord; + } + + @JsonIgnore + public String getFirstWord() { + return firstWord.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue firstWord() { + return firstWord; + } + + @JsonIgnore + public String getSecondWord() { + return secondWord.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue secondWord() { + return secondWord; + } + + /** Return true if this addKeyword object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + AddKeywordImpl addKeyword = (AddKeywordImpl) o; + return Objects.equals(this.firstWord, addKeyword.firstWord) + && Objects.equals(this.secondWord, addKeyword.secondWord); + } + + @Override + public int hashCode() { + return Objects.hash(firstWord, secondWord); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class AddKeywordImpl {\n"); + sb.append(" firstWord: ").append(toIndentedString(firstWord)).append("\n"); + sb.append(" secondWord: ").append(toIndentedString(secondWord)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements AddKeyword.Builder { + OptionalValue firstWord = OptionalValue.empty(); + OptionalValue secondWord = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + public Builder setFirstWord(String firstWord) { + this.firstWord = OptionalValue.of(firstWord); + return this; + } + + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + public Builder setSecondWord(String secondWord) { + this.secondWord = OptionalValue.of(secondWord); + return this; + } + + public AddKeyword build() { + return new AddKeywordImpl(firstWord, secondWord); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/Group.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/Group.java new file mode 100644 index 000000000..76b870925 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/Group.java @@ -0,0 +1,162 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.Instant; +import java.util.Set; + +/** Group */ +@JsonDeserialize(builder = GroupImpl.Builder.class) +public interface Group { + + /** + * The ID used to reference this group. + * + * @return id + * @readOnly This field is returned by the server and cannot be modified + */ + String getId(); + + /** + * Name of group if set. + * + * @return name + */ + String getName(); + + /** + * The number of members currently in the group. + * + * @return size + * @readOnly This field is returned by the server and cannot be modified + */ + Integer getSize(); + + /** + * Timestamp for group creation. Format: YYYY-MM-DDThh:mm:ss.SSSZ + * + * @return createdAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getCreatedAt(); + + /** + * Timestamp for when the group was last updated. Format: YYYY-MM-DDThh:mm:ss.SSSZ + * + * @return modifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getModifiedAt(); + + /** + * Get autoUpdate + * + * @return autoUpdate + */ + GroupAutoUpdate getAutoUpdate(); + + /** + * Phone numbers MSIDNs of + * child group will be included in this group. If present then this group will be auto populated. + * Constraints: Elements must be group IDs. + * + * @return childGroups + */ + Set getChildGroups(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new GroupImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setId(String id); + + /** + * see getter + * + * @param name see getter + * @return Current builder + * @see #getName + */ + Builder setName(String name); + + /** + * see getter + * + * @param size see getter + * @return Current builder + * @see #getSize + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setSize(Integer size); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param modifiedAt see getter + * @return Current builder + * @see #getModifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setModifiedAt(Instant modifiedAt); + + /** + * see getter + * + * @param autoUpdate see getter + * @return Current builder + * @see #getAutoUpdate + */ + Builder setAutoUpdate(GroupAutoUpdate autoUpdate); + + /** + * see getter + * + * @param childGroups see getter + * @return Current builder + * @see #getChildGroups + */ + Builder setChildGroups(Set childGroups); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + Group build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdate.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdate.java new file mode 100644 index 000000000..71ee0052d --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdate.java @@ -0,0 +1,89 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** GroupAutoUpdate */ +@JsonDeserialize(builder = GroupAutoUpdateImpl.Builder.class) +public interface GroupAutoUpdate { + + /** + * Short code or long number addressed in MO. + * Constraints: Must be valid phone number or short code which has been provisioned by + * your account manager. + * + * @return to + */ + String getTo(); + + /** + * Get add + * + * @return add + */ + AddKeyword getAdd(); + + /** + * Get remove + * + * @return remove + */ + RemoveKeyword getRemove(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new GroupAutoUpdateImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param to see getter + * @return Current builder + * @see #getTo + */ + Builder setTo(String to); + + /** + * see getter + * + * @param add see getter + * @return Current builder + * @see #getAdd + */ + Builder setAdd(AddKeyword add); + + /** + * see getter + * + * @param remove see getter + * @return Current builder + * @see #getRemove + */ + Builder setRemove(RemoveKeyword remove); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + GroupAutoUpdate build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdateImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdateImpl.java new file mode 100644 index 000000000..acc2ec116 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupAutoUpdateImpl.java @@ -0,0 +1,147 @@ +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +@JsonPropertyOrder({ + GroupAutoUpdateImpl.JSON_PROPERTY_TO, + GroupAutoUpdateImpl.JSON_PROPERTY_ADD, + GroupAutoUpdateImpl.JSON_PROPERTY_REMOVE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class GroupAutoUpdateImpl implements GroupAutoUpdate { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TO = "to"; + + private OptionalValue to; + + public static final String JSON_PROPERTY_ADD = "add"; + + private OptionalValue add; + + public static final String JSON_PROPERTY_REMOVE = "remove"; + + private OptionalValue remove; + + public GroupAutoUpdateImpl() {} + + protected GroupAutoUpdateImpl( + OptionalValue to, + OptionalValue add, + OptionalValue remove) { + this.to = to; + this.add = add; + this.remove = remove; + } + + @JsonIgnore + public String getTo() { + return to.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TO) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue to() { + return to; + } + + @JsonIgnore + public AddKeyword getAdd() { + return add.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue add() { + return add; + } + + @JsonIgnore + public RemoveKeyword getRemove() { + return remove.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue remove() { + return remove; + } + + /** Return true if this ApiGroupAutoUpdate object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GroupAutoUpdateImpl apiGroupAutoUpdate = (GroupAutoUpdateImpl) o; + return Objects.equals(this.to, apiGroupAutoUpdate.to) + && Objects.equals(this.add, apiGroupAutoUpdate.add) + && Objects.equals(this.remove, apiGroupAutoUpdate.remove); + } + + @Override + public int hashCode() { + return Objects.hash(to, add, remove); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class GroupAutoUpdateImpl {\n"); + sb.append(" to: ").append(toIndentedString(to)).append("\n"); + sb.append(" add: ").append(toIndentedString(add)).append("\n"); + sb.append(" remove: ").append(toIndentedString(remove)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements GroupAutoUpdate.Builder { + OptionalValue to = OptionalValue.empty(); + OptionalValue add = OptionalValue.empty(); + OptionalValue remove = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TO) + public Builder setTo(String to) { + this.to = OptionalValue.of(to); + return this; + } + + @JsonProperty(JSON_PROPERTY_ADD) + public Builder setAdd(AddKeyword add) { + this.add = OptionalValue.of(add); + return this; + } + + @JsonProperty(JSON_PROPERTY_REMOVE) + public Builder setRemove(RemoveKeyword remove) { + this.remove = OptionalValue.of(remove); + return this; + } + + public GroupAutoUpdate build() { + return new GroupAutoUpdateImpl(to, add, remove); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupImpl.java new file mode 100644 index 000000000..6e7724c47 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/GroupImpl.java @@ -0,0 +1,253 @@ +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.time.Instant; +import java.util.Objects; +import java.util.Set; + +@JsonPropertyOrder({ + GroupImpl.JSON_PROPERTY_ID, + GroupImpl.JSON_PROPERTY_NAME, + GroupImpl.JSON_PROPERTY_SIZE, + GroupImpl.JSON_PROPERTY_CREATED_AT, + GroupImpl.JSON_PROPERTY_MODIFIED_AT, + GroupImpl.JSON_PROPERTY_AUTO_UPDATE, + GroupImpl.JSON_PROPERTY_CHILD_GROUPS +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class GroupImpl implements Group { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_NAME = "name"; + + private OptionalValue name; + + public static final String JSON_PROPERTY_SIZE = "size"; + + private OptionalValue size; + + public static final String JSON_PROPERTY_CREATED_AT = "created_at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_MODIFIED_AT = "modified_at"; + + private OptionalValue modifiedAt; + + public static final String JSON_PROPERTY_AUTO_UPDATE = "auto_update"; + + private OptionalValue autoUpdate; + + public static final String JSON_PROPERTY_CHILD_GROUPS = "child_groups"; + + private OptionalValue> childGroups; + + public GroupImpl() {} + + protected GroupImpl( + OptionalValue id, + OptionalValue name, + OptionalValue size, + OptionalValue createdAt, + OptionalValue modifiedAt, + OptionalValue autoUpdate, + OptionalValue> childGroups) { + this.id = id; + this.name = name; + this.size = size; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.autoUpdate = autoUpdate; + this.childGroups = childGroups; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonIgnore + public OptionalValue id() { + return id; + } + + @JsonIgnore + public String getName() { + return name.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue name() { + return name; + } + + @JsonIgnore + public Integer getSize() { + return size.orElse(null); + } + + @JsonIgnore + public OptionalValue size() { + return size; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonIgnore + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public Instant getModifiedAt() { + return modifiedAt.orElse(null); + } + + @JsonIgnore + public OptionalValue modifiedAt() { + return modifiedAt; + } + + @JsonIgnore + public GroupAutoUpdate getAutoUpdate() { + return autoUpdate.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue autoUpdate() { + return autoUpdate; + } + + @JsonIgnore + public Set getChildGroups() { + return childGroups.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CHILD_GROUPS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> childGroups() { + return childGroups; + } + + /** Return true if this ApiGroup object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GroupImpl apiGroup = (GroupImpl) o; + return Objects.equals(this.id, apiGroup.id) + && Objects.equals(this.name, apiGroup.name) + && Objects.equals(this.size, apiGroup.size) + && Objects.equals(this.createdAt, apiGroup.createdAt) + && Objects.equals(this.modifiedAt, apiGroup.modifiedAt) + && Objects.equals(this.autoUpdate, apiGroup.autoUpdate) + && Objects.equals(this.childGroups, apiGroup.childGroups); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, size, createdAt, modifiedAt, autoUpdate, childGroups); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class GroupImpl {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" size: ").append(toIndentedString(size)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" modifiedAt: ").append(toIndentedString(modifiedAt)).append("\n"); + sb.append(" autoUpdate: ").append(toIndentedString(autoUpdate)).append("\n"); + sb.append(" childGroups: ").append(toIndentedString(childGroups)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements Group.Builder { + OptionalValue id = OptionalValue.empty(); + OptionalValue name = OptionalValue.empty(); + OptionalValue size = OptionalValue.empty(); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue modifiedAt = OptionalValue.empty(); + OptionalValue autoUpdate = OptionalValue.empty(); + OptionalValue> childGroups = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_NAME) + public Builder setName(String name) { + this.name = OptionalValue.of(name); + return this; + } + + @JsonProperty(JSON_PROPERTY_SIZE) + public Builder setSize(Integer size) { + this.size = OptionalValue.of(size); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATED_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) + public Builder setModifiedAt(Instant modifiedAt) { + this.modifiedAt = OptionalValue.of(modifiedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + public Builder setAutoUpdate(GroupAutoUpdate autoUpdate) { + this.autoUpdate = OptionalValue.of(autoUpdate); + return this; + } + + @JsonProperty(JSON_PROPERTY_CHILD_GROUPS) + public Builder setChildGroups(Set childGroups) { + this.childGroups = OptionalValue.of(childGroups); + return this; + } + + public Group build() { + return new GroupImpl(id, name, size, createdAt, modifiedAt, autoUpdate, childGroups); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeyword.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeyword.java new file mode 100644 index 000000000..a7e526205 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeyword.java @@ -0,0 +1,71 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** Keyword to be sent in MO to remove MSISDN to a group */ +@JsonDeserialize(builder = RemoveKeywordImpl.Builder.class) +public interface RemoveKeyword { + + /** + * Opt-out keyword like "LEAVE" if auto_update.to is dedicated long/short + * number or unique brand keyword like "Sinch" if it is a shared short code. + * + * @return firstWord + */ + String getFirstWord(); + + /** + * Opt-out keyword like "LEAVE" if auto_update.to is shared short code. + * + * @return secondWord + */ + String getSecondWord(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new RemoveKeywordImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param firstWord see getter + * @return Current builder + * @see #getFirstWord + */ + Builder setFirstWord(String firstWord); + + /** + * see getter + * + * @param secondWord see getter + * @return Current builder + * @see #getSecondWord + */ + Builder setSecondWord(String secondWord); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + RemoveKeyword build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeywordImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeywordImpl.java new file mode 100644 index 000000000..0d6eac795 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/RemoveKeywordImpl.java @@ -0,0 +1,118 @@ +package com.sinch.sdk.domains.sms.models.v1.groups; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +@JsonPropertyOrder({ + RemoveKeywordImpl.JSON_PROPERTY_FIRST_WORD, + RemoveKeywordImpl.JSON_PROPERTY_SECOND_WORD +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class RemoveKeywordImpl implements RemoveKeyword { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_FIRST_WORD = "first_word"; + + private OptionalValue firstWord; + + public static final String JSON_PROPERTY_SECOND_WORD = "second_word"; + + private OptionalValue secondWord; + + public RemoveKeywordImpl() {} + + protected RemoveKeywordImpl(OptionalValue firstWord, OptionalValue secondWord) { + this.firstWord = firstWord; + this.secondWord = secondWord; + } + + @JsonIgnore + public String getFirstWord() { + return firstWord.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue firstWord() { + return firstWord; + } + + @JsonIgnore + public String getSecondWord() { + return secondWord.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue secondWord() { + return secondWord; + } + + /** Return true if this removeKeyword object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + RemoveKeywordImpl removeKeyword = (RemoveKeywordImpl) o; + return Objects.equals(this.firstWord, removeKeyword.firstWord) + && Objects.equals(this.secondWord, removeKeyword.secondWord); + } + + @Override + public int hashCode() { + return Objects.hash(firstWord, secondWord); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class RemoveKeywordImpl {\n"); + sb.append(" firstWord: ").append(toIndentedString(firstWord)).append("\n"); + sb.append(" secondWord: ").append(toIndentedString(secondWord)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements RemoveKeyword.Builder { + OptionalValue firstWord = OptionalValue.empty(); + OptionalValue secondWord = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_FIRST_WORD) + public Builder setFirstWord(String firstWord) { + this.firstWord = OptionalValue.of(firstWord); + return this; + } + + @JsonProperty(JSON_PROPERTY_SECOND_WORD) + public Builder setSecondWord(String secondWord) { + this.secondWord = OptionalValue.of(secondWord); + return this; + } + + public RemoveKeyword build() { + return new RemoveKeywordImpl(firstWord, secondWord); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java new file mode 100644 index 000000000..102c51329 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java @@ -0,0 +1,181 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; +import java.time.Instant; +import java.util.Set; + +/** GroupRequest */ +@JsonDeserialize(builder = GroupRequestImpl.Builder.class) +public interface GroupRequest { + + /** + * The ID used to reference this group. + * + * @return id + * @readOnly This field is returned by the server and cannot be modified + */ + String getId(); + + /** + * Name of group if set. + * + * @return name + */ + String getName(); + + /** + * The number of members currently in the group. + * + * @return size + * @readOnly This field is returned by the server and cannot be modified + */ + Integer getSize(); + + /** + * Timestamp for group creation. Format: YYYY-MM-DDThh:mm:ss.SSSZ + * + * @return createdAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getCreatedAt(); + + /** + * Timestamp for when the group was last updated. Format: YYYY-MM-DDThh:mm:ss.SSSZ + * + * @return modifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Instant getModifiedAt(); + + /** + * Get autoUpdate + * + * @return autoUpdate + */ + GroupAutoUpdate getAutoUpdate(); + + /** + * Phone numbers MSIDNs of + * child group will be included in this group. If present then this group will be auto populated. + * Constraints: Elements must be group IDs. + * + * @return childGroups + */ + Set getChildGroups(); + + /** + * Initial list of phone numbers in E.164 format MSISDNs for the group. + * + * @return members + */ + Set getMembers(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new GroupRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setId(String id); + + /** + * see getter + * + * @param name see getter + * @return Current builder + * @see #getName + */ + Builder setName(String name); + + /** + * see getter + * + * @param size see getter + * @return Current builder + * @see #getSize + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setSize(Integer size); + + /** + * see getter + * + * @param createdAt see getter + * @return Current builder + * @see #getCreatedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setCreatedAt(Instant createdAt); + + /** + * see getter + * + * @param modifiedAt see getter + * @return Current builder + * @see #getModifiedAt + * @readOnly This field is returned by the server and cannot be modified + */ + Builder setModifiedAt(Instant modifiedAt); + + /** + * see getter + * + * @param autoUpdate see getter + * @return Current builder + * @see #getAutoUpdate + */ + Builder setAutoUpdate(GroupAutoUpdate autoUpdate); + + /** + * see getter + * + * @param childGroups see getter + * @return Current builder + * @see #getChildGroups + */ + Builder setChildGroups(Set childGroups); + + /** + * see getter + * + * @param members see getter + * @return Current builder + * @see #getMembers + */ + Builder setMembers(Set members); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + GroupRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestImpl.java new file mode 100644 index 000000000..380a412ba --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequestImpl.java @@ -0,0 +1,282 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; +import java.time.Instant; +import java.util.Objects; +import java.util.Set; + +@JsonPropertyOrder({ + GroupRequestImpl.JSON_PROPERTY_ID, + GroupRequestImpl.JSON_PROPERTY_NAME, + GroupRequestImpl.JSON_PROPERTY_SIZE, + GroupRequestImpl.JSON_PROPERTY_CREATED_AT, + GroupRequestImpl.JSON_PROPERTY_MODIFIED_AT, + GroupRequestImpl.JSON_PROPERTY_AUTO_UPDATE, + GroupRequestImpl.JSON_PROPERTY_CHILD_GROUPS, + GroupRequestImpl.JSON_PROPERTY_MEMBERS +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class GroupRequestImpl implements GroupRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_NAME = "name"; + + private OptionalValue name; + + public static final String JSON_PROPERTY_SIZE = "size"; + + private OptionalValue size; + + public static final String JSON_PROPERTY_CREATED_AT = "created_at"; + + private OptionalValue createdAt; + + public static final String JSON_PROPERTY_MODIFIED_AT = "modified_at"; + + private OptionalValue modifiedAt; + + public static final String JSON_PROPERTY_AUTO_UPDATE = "auto_update"; + + private OptionalValue autoUpdate; + + public static final String JSON_PROPERTY_CHILD_GROUPS = "child_groups"; + + private OptionalValue> childGroups; + + public static final String JSON_PROPERTY_MEMBERS = "members"; + + private OptionalValue> members; + + public GroupRequestImpl() {} + + protected GroupRequestImpl( + OptionalValue id, + OptionalValue name, + OptionalValue size, + OptionalValue createdAt, + OptionalValue modifiedAt, + OptionalValue autoUpdate, + OptionalValue> childGroups, + OptionalValue> members) { + this.id = id; + this.name = name; + this.size = size; + this.createdAt = createdAt; + this.modifiedAt = modifiedAt; + this.autoUpdate = autoUpdate; + this.childGroups = childGroups; + this.members = members; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonIgnore + public OptionalValue id() { + return id; + } + + @JsonIgnore + public String getName() { + return name.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue name() { + return name; + } + + @JsonIgnore + public Integer getSize() { + return size.orElse(null); + } + + @JsonIgnore + public OptionalValue size() { + return size; + } + + @JsonIgnore + public Instant getCreatedAt() { + return createdAt.orElse(null); + } + + @JsonIgnore + public OptionalValue createdAt() { + return createdAt; + } + + @JsonIgnore + public Instant getModifiedAt() { + return modifiedAt.orElse(null); + } + + @JsonIgnore + public OptionalValue modifiedAt() { + return modifiedAt; + } + + @JsonIgnore + public GroupAutoUpdate getAutoUpdate() { + return autoUpdate.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue autoUpdate() { + return autoUpdate; + } + + @JsonIgnore + public Set getChildGroups() { + return childGroups.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CHILD_GROUPS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> childGroups() { + return childGroups; + } + + @JsonIgnore + public Set getMembers() { + return members.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MEMBERS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> members() { + return members; + } + + /** Return true if this ApiGroupRequest object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GroupRequestImpl apiGroupRequest = (GroupRequestImpl) o; + return Objects.equals(this.id, apiGroupRequest.id) + && Objects.equals(this.name, apiGroupRequest.name) + && Objects.equals(this.size, apiGroupRequest.size) + && Objects.equals(this.createdAt, apiGroupRequest.createdAt) + && Objects.equals(this.modifiedAt, apiGroupRequest.modifiedAt) + && Objects.equals(this.autoUpdate, apiGroupRequest.autoUpdate) + && Objects.equals(this.childGroups, apiGroupRequest.childGroups) + && Objects.equals(this.members, apiGroupRequest.members); + } + + @Override + public int hashCode() { + return Objects.hash(id, name, size, createdAt, modifiedAt, autoUpdate, childGroups, members); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class GroupRequestImpl {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" size: ").append(toIndentedString(size)).append("\n"); + sb.append(" createdAt: ").append(toIndentedString(createdAt)).append("\n"); + sb.append(" modifiedAt: ").append(toIndentedString(modifiedAt)).append("\n"); + sb.append(" autoUpdate: ").append(toIndentedString(autoUpdate)).append("\n"); + sb.append(" childGroups: ").append(toIndentedString(childGroups)).append("\n"); + sb.append(" members: ").append(toIndentedString(members)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements GroupRequest.Builder { + OptionalValue id = OptionalValue.empty(); + OptionalValue name = OptionalValue.empty(); + OptionalValue size = OptionalValue.empty(); + OptionalValue createdAt = OptionalValue.empty(); + OptionalValue modifiedAt = OptionalValue.empty(); + OptionalValue autoUpdate = OptionalValue.empty(); + OptionalValue> childGroups = OptionalValue.empty(); + OptionalValue> members = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_NAME) + public Builder setName(String name) { + this.name = OptionalValue.of(name); + return this; + } + + @JsonProperty(JSON_PROPERTY_SIZE) + public Builder setSize(Integer size) { + this.size = OptionalValue.of(size); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATED_AT) + public Builder setCreatedAt(Instant createdAt) { + this.createdAt = OptionalValue.of(createdAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_MODIFIED_AT) + public Builder setModifiedAt(Instant modifiedAt) { + this.modifiedAt = OptionalValue.of(modifiedAt); + return this; + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + public Builder setAutoUpdate(GroupAutoUpdate autoUpdate) { + this.autoUpdate = OptionalValue.of(autoUpdate); + return this; + } + + @JsonProperty(JSON_PROPERTY_CHILD_GROUPS) + public Builder setChildGroups(Set childGroups) { + this.childGroups = OptionalValue.of(childGroups); + return this; + } + + @JsonProperty(JSON_PROPERTY_MEMBERS) + public Builder setMembers(Set members) { + this.members = OptionalValue.of(members); + return this; + } + + public GroupRequest build() { + return new GroupRequestImpl( + id, name, size, createdAt, modifiedAt, autoUpdate, childGroups, members); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequest.java new file mode 100644 index 000000000..2aaea8910 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequest.java @@ -0,0 +1,141 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; +import java.util.List; + +/** GroupUpdateRequest */ +@JsonDeserialize(builder = GroupUpdateRequestImpl.Builder.class) +public interface GroupUpdateRequest { + + /** + * Add a list of phone numbers (MSISDNs) to this group. The phone numbers are a strings within an + * array and must be in E.164 + * format. + * + * @return add + */ + List getAdd(); + + /** + * Remove a list of phone numbers (MSISDNs) to this group.The phone numbers are a strings within + * an array and must be in E.164 + * format. + * + * @return remove + */ + List getRemove(); + + /** + * The name of the group. Omitting name from the JSON body will leave the name + * unchanged. To remove an existing name set, name explicitly to the JSON value null. + * + * @return name + */ + String getName(); + + /** + * One time copy of all members from the group referenced by the group ID into this group. + * + * @return addFromGroup + */ + String getAddFromGroup(); + + /** + * Remove all members from this group that are currently in the group referenced by the group ID. + * + * @return removeFromGroup + */ + String getRemoveFromGroup(); + + /** + * Get autoUpdate + * + * @return autoUpdate + */ + GroupAutoUpdate getAutoUpdate(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new GroupUpdateRequestImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param add see getter + * @return Current builder + * @see #getAdd + */ + Builder setAdd(List add); + + /** + * see getter + * + * @param remove see getter + * @return Current builder + * @see #getRemove + */ + Builder setRemove(List remove); + + /** + * see getter + * + * @param name see getter + * @return Current builder + * @see #getName + */ + Builder setName(String name); + + /** + * see getter + * + * @param addFromGroup see getter + * @return Current builder + * @see #getAddFromGroup + */ + Builder setAddFromGroup(String addFromGroup); + + /** + * see getter + * + * @param removeFromGroup see getter + * @return Current builder + * @see #getRemoveFromGroup + */ + Builder setRemoveFromGroup(String removeFromGroup); + + /** + * see getter + * + * @param autoUpdate see getter + * @return Current builder + * @see #getAutoUpdate + */ + Builder setAutoUpdate(GroupAutoUpdate autoUpdate); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + GroupUpdateRequest build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestImpl.java new file mode 100644 index 000000000..613c53cd0 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestImpl.java @@ -0,0 +1,231 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + GroupUpdateRequestImpl.JSON_PROPERTY_ADD, + GroupUpdateRequestImpl.JSON_PROPERTY_REMOVE, + GroupUpdateRequestImpl.JSON_PROPERTY_NAME, + GroupUpdateRequestImpl.JSON_PROPERTY_ADD_FROM_GROUP, + GroupUpdateRequestImpl.JSON_PROPERTY_REMOVE_FROM_GROUP, + GroupUpdateRequestImpl.JSON_PROPERTY_AUTO_UPDATE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class GroupUpdateRequestImpl implements GroupUpdateRequest { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ADD = "add"; + + private OptionalValue> add; + + public static final String JSON_PROPERTY_REMOVE = "remove"; + + private OptionalValue> remove; + + public static final String JSON_PROPERTY_NAME = "name"; + + private OptionalValue name; + + public static final String JSON_PROPERTY_ADD_FROM_GROUP = "add_from_group"; + + private OptionalValue addFromGroup; + + public static final String JSON_PROPERTY_REMOVE_FROM_GROUP = "remove_from_group"; + + private OptionalValue removeFromGroup; + + public static final String JSON_PROPERTY_AUTO_UPDATE = "auto_update"; + + private OptionalValue autoUpdate; + + public GroupUpdateRequestImpl() {} + + protected GroupUpdateRequestImpl( + OptionalValue> add, + OptionalValue> remove, + OptionalValue name, + OptionalValue addFromGroup, + OptionalValue removeFromGroup, + OptionalValue autoUpdate) { + this.add = add; + this.remove = remove; + this.name = name; + this.addFromGroup = addFromGroup; + this.removeFromGroup = removeFromGroup; + this.autoUpdate = autoUpdate; + } + + @JsonIgnore + public List getAdd() { + return add.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ADD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> add() { + return add; + } + + @JsonIgnore + public List getRemove() { + return remove.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_REMOVE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> remove() { + return remove; + } + + @JsonIgnore + public String getName() { + return name.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue name() { + return name; + } + + @JsonIgnore + public String getAddFromGroup() { + return addFromGroup.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ADD_FROM_GROUP) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue addFromGroup() { + return addFromGroup; + } + + @JsonIgnore + public String getRemoveFromGroup() { + return removeFromGroup.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_REMOVE_FROM_GROUP) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue removeFromGroup() { + return removeFromGroup; + } + + @JsonIgnore + public GroupAutoUpdate getAutoUpdate() { + return autoUpdate.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue autoUpdate() { + return autoUpdate; + } + + /** Return true if this ApiGroupUpdate object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GroupUpdateRequestImpl apiGroupUpdate = (GroupUpdateRequestImpl) o; + return Objects.equals(this.add, apiGroupUpdate.add) + && Objects.equals(this.remove, apiGroupUpdate.remove) + && Objects.equals(this.name, apiGroupUpdate.name) + && Objects.equals(this.addFromGroup, apiGroupUpdate.addFromGroup) + && Objects.equals(this.removeFromGroup, apiGroupUpdate.removeFromGroup) + && Objects.equals(this.autoUpdate, apiGroupUpdate.autoUpdate); + } + + @Override + public int hashCode() { + return Objects.hash(add, remove, name, addFromGroup, removeFromGroup, autoUpdate); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class GroupUpdateRequestImpl {\n"); + sb.append(" add: ").append(toIndentedString(add)).append("\n"); + sb.append(" remove: ").append(toIndentedString(remove)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" addFromGroup: ").append(toIndentedString(addFromGroup)).append("\n"); + sb.append(" removeFromGroup: ").append(toIndentedString(removeFromGroup)).append("\n"); + sb.append(" autoUpdate: ").append(toIndentedString(autoUpdate)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements GroupUpdateRequest.Builder { + OptionalValue> add = OptionalValue.empty(); + OptionalValue> remove = OptionalValue.empty(); + OptionalValue name = OptionalValue.empty(); + OptionalValue addFromGroup = OptionalValue.empty(); + OptionalValue removeFromGroup = OptionalValue.empty(); + OptionalValue autoUpdate = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ADD) + public Builder setAdd(List add) { + this.add = OptionalValue.of(add); + return this; + } + + @JsonProperty(JSON_PROPERTY_REMOVE) + public Builder setRemove(List remove) { + this.remove = OptionalValue.of(remove); + return this; + } + + @JsonProperty(JSON_PROPERTY_NAME) + public Builder setName(String name) { + this.name = OptionalValue.of(name); + return this; + } + + @JsonProperty(JSON_PROPERTY_ADD_FROM_GROUP) + public Builder setAddFromGroup(String addFromGroup) { + this.addFromGroup = OptionalValue.of(addFromGroup); + return this; + } + + @JsonProperty(JSON_PROPERTY_REMOVE_FROM_GROUP) + public Builder setRemoveFromGroup(String removeFromGroup) { + this.removeFromGroup = OptionalValue.of(removeFromGroup); + return this; + } + + @JsonProperty(JSON_PROPERTY_AUTO_UPDATE) + public Builder setAutoUpdate(GroupAutoUpdate autoUpdate) { + this.autoUpdate = OptionalValue.of(autoUpdate); + return this; + } + + public GroupUpdateRequest build() { + return new GroupUpdateRequestImpl( + add, remove, name, addFromGroup, removeFromGroup, autoUpdate); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParameters.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParameters.java new file mode 100644 index 000000000..b7a043fe5 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParameters.java @@ -0,0 +1,78 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.sinch.sdk.core.models.OptionalValue; + +/** ListGroupsQueryParameters */ +public interface ListGroupsQueryParameters { + + /** + * Get page minimum: 0 + * + * @return page + */ + OptionalValue getPage(); + + /** + * Get pageSize minimum: 0 maximum: 100 + * + * @return pageSize + */ + OptionalValue getPageSize(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ListGroupsQueryParametersImpl.Builder(); + } + + /** + * Getting builder from existing instance + * + * @return New Builder instance + */ + static Builder builder(ListGroupsQueryParameters parameters) { + return new ListGroupsQueryParametersImpl.Builder(parameters); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ListGroupsQueryParameters build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParametersImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParametersImpl.java new file mode 100644 index 000000000..be0e02afd --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/ListGroupsQueryParametersImpl.java @@ -0,0 +1,93 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.request; + +import com.sinch.sdk.core.models.OptionalValue; +import java.util.Objects; + +public class ListGroupsQueryParametersImpl implements ListGroupsQueryParameters { + + private final OptionalValue page; + private final OptionalValue pageSize; + + private ListGroupsQueryParametersImpl( + OptionalValue page, OptionalValue pageSize) { + this.page = page; + this.pageSize = pageSize; + } + + public OptionalValue getPage() { + return page; + } + + public OptionalValue getPageSize() { + return pageSize; + } + + /** Return true if this ListGroupsQueryParameters object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ListGroupsQueryParametersImpl listGroupsQueryParameters = (ListGroupsQueryParametersImpl) o; + return Objects.equals(this.page, listGroupsQueryParameters.page) + && Objects.equals(this.pageSize, listGroupsQueryParameters.pageSize); + } + + @Override + public int hashCode() { + return Objects.hash(page, pageSize); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ListGroupsQueryParametersImpl {\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).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 "); + } + + static class Builder implements ListGroupsQueryParameters.Builder { + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + + protected Builder() {} + + protected Builder(ListGroupsQueryParameters _parameters) { + if (null == _parameters) { + return; + } + ListGroupsQueryParametersImpl parameters = (ListGroupsQueryParametersImpl) _parameters; + this.page = parameters.getPage(); + this.pageSize = parameters.getPageSize(); + } + + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + public ListGroupsQueryParameters build() { + return new ListGroupsQueryParametersImpl(page, pageSize); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java new file mode 100644 index 000000000..5a0191d7b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java @@ -0,0 +1,104 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.models.v1.groups.response.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import java.util.List; + +/** ApiGroupList */ +@JsonDeserialize(builder = ApiGroupListImpl.Builder.class) +public interface ApiGroupList { + + /** + * The requested page. + * + * @return page + */ + Integer getPage(); + + /** + * The number of groups returned in this request + * + * @return pageSize + */ + Integer getPageSize(); + + /** + * The total number of groups. + * + * @return count + */ + Integer getCount(); + + /** + * Get groups + * + * @return groups + */ + List getGroups(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ApiGroupListImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param page see getter + * @return Current builder + * @see #getPage + */ + Builder setPage(Integer page); + + /** + * see getter + * + * @param pageSize see getter + * @return Current builder + * @see #getPageSize + */ + Builder setPageSize(Integer pageSize); + + /** + * see getter + * + * @param count see getter + * @return Current builder + * @see #getCount + */ + Builder setCount(Integer count); + + /** + * see getter + * + * @param groups see getter + * @return Current builder + * @see #getGroups + */ + Builder setGroups(List groups); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ApiGroupList build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java new file mode 100644 index 000000000..89355628c --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java @@ -0,0 +1,176 @@ +package com.sinch.sdk.domains.sms.models.v1.groups.response.internal; + +import com.fasterxml.jackson.annotation.JsonFilter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + ApiGroupListImpl.JSON_PROPERTY_PAGE, + ApiGroupListImpl.JSON_PROPERTY_PAGE_SIZE, + ApiGroupListImpl.JSON_PROPERTY_COUNT, + ApiGroupListImpl.JSON_PROPERTY_GROUPS +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class ApiGroupListImpl implements ApiGroupList { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_PAGE = "page"; + + private OptionalValue page; + + public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; + + private OptionalValue pageSize; + + public static final String JSON_PROPERTY_COUNT = "count"; + + private OptionalValue count; + + public static final String JSON_PROPERTY_GROUPS = "groups"; + + private OptionalValue> groups; + + public ApiGroupListImpl() {} + + protected ApiGroupListImpl( + OptionalValue page, + OptionalValue pageSize, + OptionalValue count, + OptionalValue> groups) { + this.page = page; + this.pageSize = pageSize; + this.count = count; + this.groups = groups; + } + + @JsonIgnore + public Integer getPage() { + return page.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue page() { + return page; + } + + @JsonIgnore + public Integer getPageSize() { + return pageSize.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue pageSize() { + return pageSize; + } + + @JsonIgnore + public Integer getCount() { + return count.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_COUNT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue count() { + return count; + } + + @JsonIgnore + public List getGroups() { + return groups.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_GROUPS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> groups() { + return groups; + } + + /** Return true if this ApiGroupList object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ApiGroupListImpl apiGroupList = (ApiGroupListImpl) o; + return Objects.equals(this.page, apiGroupList.page) + && Objects.equals(this.pageSize, apiGroupList.pageSize) + && Objects.equals(this.count, apiGroupList.count) + && Objects.equals(this.groups, apiGroupList.groups); + } + + @Override + public int hashCode() { + return Objects.hash(page, pageSize, count, groups); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ApiGroupListImpl {\n"); + sb.append(" page: ").append(toIndentedString(page)).append("\n"); + sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); + sb.append(" count: ").append(toIndentedString(count)).append("\n"); + sb.append(" groups: ").append(toIndentedString(groups)).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 "); + } + + @JsonPOJOBuilder(withPrefix = "set") + static class Builder implements ApiGroupList.Builder { + OptionalValue page = OptionalValue.empty(); + OptionalValue pageSize = OptionalValue.empty(); + OptionalValue count = OptionalValue.empty(); + OptionalValue> groups = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_PAGE) + public Builder setPage(Integer page) { + this.page = OptionalValue.of(page); + return this; + } + + @JsonProperty(JSON_PROPERTY_PAGE_SIZE) + public Builder setPageSize(Integer pageSize) { + this.pageSize = OptionalValue.of(pageSize); + return this; + } + + @JsonProperty(JSON_PROPERTY_COUNT) + public Builder setCount(Integer count) { + this.count = OptionalValue.of(count); + return this; + } + + @JsonProperty(JSON_PROPERTY_GROUPS) + public Builder setGroups(List groups) { + this.groups = OptionalValue.of(groups); + return this; + } + + public ApiGroupList build() { + return new ApiGroupListImpl(page, pageSize, count, groups); + } + } +} From 51a809714161fd5a8883bc652093bbe3e4eb9093 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 14 Jan 2025 07:43:18 +0100 Subject: [PATCH 48/65] feat (SMS/Webhooks): Support 'validateAuthenticationHeader' helper for SMS webhooks. Hmac validation shared with converstion --- .../HmacAuthenticationValidation.java} | 14 ++--- .../api/v1/adapters/ConversationService.java | 7 +-- .../api/v1/adapters/WebHooksService.java | 5 +- .../domains/sms/api/v1/WebHooksService.java | 4 ++ .../sms/api/v1/adapters/SMSService.java | 3 +- .../sms/api/v1/adapters/WebHooksService.java | 14 +++++ .../HmacAuthenticationValidationTest.java} | 40 ++++---------- .../adapters/WebHooksClientServiceTest.java | 3 +- .../api/v1/adapters/WebHooksServiceTest.java | 10 ++-- .../api/v1/adapters/WebHooksServiceTest.java | 53 ++++++++++++++++++- 10 files changed, 101 insertions(+), 52 deletions(-) rename client/src/main/com/sinch/sdk/{domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidation.java => auth/HmacAuthenticationValidation.java} (78%) rename client/src/test/java/com/sinch/sdk/{domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidationTest.java => auth/HmacAuthenticationValidationTest.java} (71%) diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidation.java b/client/src/main/com/sinch/sdk/auth/HmacAuthenticationValidation.java similarity index 78% rename from client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidation.java rename to client/src/main/com/sinch/sdk/auth/HmacAuthenticationValidation.java index f64ce1fdd..db56533e8 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidation.java +++ b/client/src/main/com/sinch/sdk/auth/HmacAuthenticationValidation.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.conversation.api.v1.adapters; +package com.sinch.sdk.auth; import com.sinch.sdk.core.exceptions.ApiAuthException; import com.sinch.sdk.core.utils.MapUtils; @@ -12,15 +12,15 @@ import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; -public class ConversationWebhooksAuthenticationValidation { +public class HmacAuthenticationValidation { private static final Logger LOGGER = - Logger.getLogger(ConversationWebhooksAuthenticationValidation.class.getName()); + Logger.getLogger(HmacAuthenticationValidation.class.getName()); - static final String TIMESTAMP_HEADER = "x-sinch-webhook-signature-timestamp"; - static final String NONCE_HEADER = "x-sinch-webhook-signature-nonce"; - static final String ALGORITHM_HEADER = "x-sinch-webhook-signature-algorithm"; - static final String SIGNATURE_HEADER = "x-sinch-webhook-signature"; + public static final String TIMESTAMP_HEADER = "x-sinch-webhook-signature-timestamp"; + public static final String NONCE_HEADER = "x-sinch-webhook-signature-nonce"; + public static final String ALGORITHM_HEADER = "x-sinch-webhook-signature-algorithm"; + public static final String SIGNATURE_HEADER = "x-sinch-webhook-signature"; public boolean validateAuthenticationHeader( String secret, Map _headers, String jsonPayload) { diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java index 96ec9192b..e05220560 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationService.java @@ -1,5 +1,6 @@ package com.sinch.sdk.domains.conversation.api.v1.adapters; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.auth.adapters.OAuthManager; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; @@ -118,11 +119,7 @@ public WebHooksService webhooks() { if (null == this.webhooks) { this.webhooks = new WebHooksService( - uriUUID, - context, - httpClient, - authManagers, - new ConversationWebhooksAuthenticationValidation()); + uriUUID, context, httpClient, authManagers, new HmacAuthenticationValidation()); } return this.webhooks; } diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksService.java index 7d53749c8..82df2fa26 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksService.java @@ -1,6 +1,7 @@ package com.sinch.sdk.domains.conversation.api.v1.adapters; import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.core.exceptions.ApiMappingException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; @@ -22,7 +23,7 @@ public class WebHooksService implements com.sinch.sdk.domains.conversation.api.v1.WebHooksService { - private final ConversationWebhooksAuthenticationValidation authenticationChecker; + private final HmacAuthenticationValidation authenticationChecker; private final String uriUUID; private final WebhooksApi api; @@ -32,7 +33,7 @@ public WebHooksService( ConversationContext context, HttpClient httpClient, Map authManagers, - ConversationWebhooksAuthenticationValidation authenticationChecker) { + HmacAuthenticationValidation authenticationChecker) { this.authenticationChecker = authenticationChecker; this.uriUUID = uriUUID; this.api = new WebhooksApi(httpClient, context.getServer(), authManagers, new HttpMapper()); diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java index 200922acf..580cfadb6 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java @@ -2,8 +2,12 @@ import com.sinch.sdk.core.exceptions.ApiMappingException; import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +import java.util.Map; public interface WebHooksService { SmsEvent parseEvent(String jsonPayload) throws ApiMappingException; + + boolean validateAuthenticationHeader( + String secret, Map headers, String jsonPayload); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index d6f08f978..975f0fdb4 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -1,5 +1,6 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.auth.adapters.BearerAuthManager; import com.sinch.sdk.auth.adapters.OAuthManager; import com.sinch.sdk.core.http.AuthManager; @@ -109,7 +110,7 @@ public DeliveryReportsService deliveryReports() { @Override public WebHooksService webhooks() { if (null == this.webhooks) { - this.webhooks = new WebHooksService(); + this.webhooks = new WebHooksService(new HmacAuthenticationValidation()); } return this.webhooks; } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java index 3993979ea..962b1de71 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksService.java @@ -1,12 +1,20 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.core.exceptions.ApiMappingException; import com.sinch.sdk.core.utils.databind.Mapper; import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +import java.util.Map; public class WebHooksService implements com.sinch.sdk.domains.sms.api.v1.WebHooksService { + private final HmacAuthenticationValidation authenticationChecker; + + public WebHooksService(HmacAuthenticationValidation authenticationChecker) { + this.authenticationChecker = authenticationChecker; + } + public SmsEvent parseEvent(String jsonPayload) throws ApiMappingException { try { @@ -15,4 +23,10 @@ public SmsEvent parseEvent(String jsonPayload) throws ApiMappingException { throw new RuntimeException(e); } } + + public boolean validateAuthenticationHeader( + String secret, Map headers, String jsonPayload) { + + return authenticationChecker.validateAuthenticationHeader(secret, headers, jsonPayload); + } } diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidationTest.java b/client/src/test/java/com/sinch/sdk/auth/HmacAuthenticationValidationTest.java similarity index 71% rename from client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidationTest.java rename to client/src/test/java/com/sinch/sdk/auth/HmacAuthenticationValidationTest.java index 6851a88f4..7d7e09273 100644 --- a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationWebhooksAuthenticationValidationTest.java +++ b/client/src/test/java/com/sinch/sdk/auth/HmacAuthenticationValidationTest.java @@ -1,4 +1,4 @@ -package com.sinch.sdk.domains.conversation.api.v1.adapters; +package com.sinch.sdk.auth; import static org.junit.jupiter.api.Assertions.*; @@ -9,23 +9,21 @@ import java.util.stream.Stream; import org.junit.jupiter.api.Test; -class ConversationWebhooksAuthenticationValidationTest { +class HmacAuthenticationValidationTest { - ConversationWebhooksAuthenticationValidation webhooksService = - new ConversationWebhooksAuthenticationValidation(); + HmacAuthenticationValidation webhooksService = new HmacAuthenticationValidation(); Map headers = Stream.of( new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.SIGNATURE_HEADER, + HmacAuthenticationValidation.SIGNATURE_HEADER, "6bpJoRmFoXVjfJIVglMoJzYXxnoxRujzR4k2GOXewOE="), new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.ALGORITHM_HEADER, "HmacSHA256"), + HmacAuthenticationValidation.ALGORITHM_HEADER, "HmacSHA256"), new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.NONCE_HEADER, - "01FJA8B4A7BM43YGWSG9GBV067"), + HmacAuthenticationValidation.NONCE_HEADER, "01FJA8B4A7BM43YGWSG9GBV067"), new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.TIMESTAMP_HEADER, "1634579353")) + HmacAuthenticationValidation.TIMESTAMP_HEADER, "1634579353")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); String secret = "foo_secret1234"; @@ -66,11 +64,7 @@ void checkValidateAuthenticatedRequestMissingSignature() { Map headerSet = headers.entrySet().stream() - .filter( - entry -> - !entry - .getKey() - .equals(ConversationWebhooksAuthenticationValidation.SIGNATURE_HEADER)) + .filter(entry -> !entry.getKey().equals(HmacAuthenticationValidation.SIGNATURE_HEADER)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); boolean authenticationResult = @@ -84,11 +78,7 @@ void checkValidateAuthenticatedRequestMissingAlgorithm() { Map headerSet = headers.entrySet().stream() - .filter( - entry -> - !entry - .getKey() - .equals(ConversationWebhooksAuthenticationValidation.ALGORITHM_HEADER)) + .filter(entry -> !entry.getKey().equals(HmacAuthenticationValidation.ALGORITHM_HEADER)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); boolean authenticationResult = @@ -102,11 +92,7 @@ void checkValidateAuthenticatedMissingNonce() { Map headerSet = headers.entrySet().stream() - .filter( - entry -> - !entry - .getKey() - .equals(ConversationWebhooksAuthenticationValidation.NONCE_HEADER)) + .filter(entry -> !entry.getKey().equals(HmacAuthenticationValidation.NONCE_HEADER)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); boolean authenticationResult = @@ -120,11 +106,7 @@ void checkValidateAuthenticatedMissingTimeStamp() { Map headerSet = headers.entrySet().stream() - .filter( - entry -> - !entry - .getKey() - .equals(ConversationWebhooksAuthenticationValidation.TIMESTAMP_HEADER)) + .filter(entry -> !entry.getKey().equals(HmacAuthenticationValidation.TIMESTAMP_HEADER)) .collect(Collectors.toMap(Entry::getKey, Entry::getValue)); boolean authenticationResult = diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksClientServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksClientServiceTest.java index 24fb82e75..f4430de81 100644 --- a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksClientServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksClientServiceTest.java @@ -8,6 +8,7 @@ import static org.mockito.Mockito.when; import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; @@ -40,7 +41,7 @@ public class WebHooksClientServiceTest extends ConversationBaseTest { @Mock WebhooksApi api; @Mock HttpClient httpClient; @Mock Map authManagers; - @Mock ConversationWebhooksAuthenticationValidation authenticationValidation; + @Mock HmacAuthenticationValidation authenticationValidation; @Captor ArgumentCaptor uriPartIDCaptor; @Captor ArgumentCaptor idCaptor; diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksServiceTest.java index d9feab74d..136dbd3ce 100644 --- a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/WebHooksServiceTest.java @@ -5,6 +5,7 @@ import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.SinchClient; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.capability.CapabilityEvent; import com.sinch.sdk.domains.conversation.models.v1.webhooks.events.channel.ChannelEvent; @@ -119,15 +120,14 @@ void checkApplicationAuthentication() throws ApiException { Map headers = Stream.of( new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.SIGNATURE_HEADER, + HmacAuthenticationValidation.SIGNATURE_HEADER, "6bpJoRmFoXVjfJIVglMoJzYXxnoxRujzR4k2GOXewOE="), new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.ALGORITHM_HEADER, "HmacSHA256"), + HmacAuthenticationValidation.ALGORITHM_HEADER, "HmacSHA256"), new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.NONCE_HEADER, - "01FJA8B4A7BM43YGWSG9GBV067"), + HmacAuthenticationValidation.NONCE_HEADER, "01FJA8B4A7BM43YGWSG9GBV067"), new AbstractMap.SimpleEntry<>( - ConversationWebhooksAuthenticationValidation.TIMESTAMP_HEADER, "1634579353")) + HmacAuthenticationValidation.TIMESTAMP_HEADER, "1634579353")) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); boolean authenticationResult = diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java index d96ba4e27..d9838badc 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/WebHooksServiceTest.java @@ -1,16 +1,26 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; +import com.sinch.sdk.SinchClient; +import com.sinch.sdk.auth.HmacAuthenticationValidation; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.api.v1.WebHooksService; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReportDtoTest; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportDtoTest; import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessageDtoTest; import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +import com.sinch.sdk.models.Configuration; +import java.util.AbstractMap; +import java.util.Map; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.InjectMocks; @TestWithResources public class WebHooksServiceTest extends BaseTest { @@ -36,7 +46,46 @@ public class WebHooksServiceTest extends BaseTest { @GivenTextResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") String loadedRecipientDeliveryReportMMSEvent; - @InjectMocks WebHooksService service; + WebHooksService service; + + @BeforeEach + public void setUp() { + + Configuration configuration = + Configuration.builder() + .setProjectId("unused") + .setKeyId("unused") + .setKeySecret("unused") + .build(); + service = new SinchClient(configuration).sms().v1().webhooks(); + } + + @Test + void checkApplicationAuthentication() throws ApiException { + + Map headers = + Stream.of( + new AbstractMap.SimpleEntry<>( + HmacAuthenticationValidation.SIGNATURE_HEADER, + "ZoHei66PPN/kZjw7hFVfGhJOnml3iGNCMWoyQVcE5o0="), + new AbstractMap.SimpleEntry<>( + HmacAuthenticationValidation.ALGORITHM_HEADER, "HmacSHA256"), + new AbstractMap.SimpleEntry<>( + HmacAuthenticationValidation.NONCE_HEADER, "01JHFFHWYY7HSS4FWTMDTQEK8V"), + new AbstractMap.SimpleEntry<>( + HmacAuthenticationValidation.TIMESTAMP_HEADER, "1736760161")) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + + boolean authenticationResult = + service.validateAuthenticationHeader( + "SMSWebhooksSecret", + headers, + "{\"at\":\"2025-01-13T09:22:40.914Z\",\"batch_id\":\"01JHFFHQ0P99JPPNQPJDV7JTBP\",\"client_reference\":\"a" + + " client" + + " reference\",\"code\":0,\"operator_status_at\":\"2025-01-13T09:22:00Z\",\"recipient\":\"33662162466\",\"status\":\"Delivered\",\"type\":\"recipient_delivery_report_sms\"}"); + + assertTrue(authenticationResult); + } @Test void incomingSMSBinary() throws ApiException { From 290f6b09bf4cc1ddeb0fd47e672f66899ddfb82f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 14 Jan 2025 10:52:02 +0100 Subject: [PATCH 49/65] test (SMS/Webhooks): Extends e2e test to support 'validateAuthenticationHeader' --- .../sdk/e2e/domains/sms/v0/WebhooksSteps.java | 10 ++++++ .../sdk/e2e/domains/sms/v1/WebhooksSteps.java | 33 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java index 13b860ab5..390644936 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v0/WebhooksSteps.java @@ -138,4 +138,14 @@ public void deliveryReportRecipientAbortedResult() { TestHelpers.recursiveEquals(deliveryReportRecipientAborted.event, expected); } + + @Then("the header of the event {string} contains a valid signature") + public void validateHeader(String _unused) { + // dummy empty validation: V0 do not support authentication + } + + @Then("the header of the event {string} with the status {string} contains a valid signature") + public void validateHeader(String _unused, String status) { + // dummy empty validation: V0 do not support authentication + } } diff --git a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java index be7ca72f0..8334f1bda 100644 --- a/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java +++ b/client/src/test/java/com/sinch/sdk/e2e/domains/sms/v1/WebhooksSteps.java @@ -19,12 +19,15 @@ import java.time.Instant; import java.util.Arrays; import java.util.HashSet; +import org.junit.jupiter.api.Assertions; public class WebhooksSteps { static final String WEBHOOKS_PATH_PREFIX = "/webhooks/sms"; static final String WEBHOOKS_URL = Config.SMS_HOST_NAME + WEBHOOKS_PATH_PREFIX; + static final String SECRET = "KayakingTheSwell"; + WebHooksService service; WebhooksHelper.Response incoming; WebhooksHelper.Response deliveryReport; @@ -139,4 +142,34 @@ public void deliveryReportRecipientAbortedResult() { TestHelpers.recursiveEquals(deliveryReportRecipientAborted.event, expected); } + + @Then("the header of the event {string} contains a valid signature") + public void validateHeader(String event) { + + WebhooksHelper.Response response = null; + if (event.equals("IncomingSMS")) { + response = incoming; + } else if (event.equals("DeliveryReport")) { + response = deliveryReport; + } + + boolean validated = + service.validateAuthenticationHeader(SECRET, response.headers, response.rawPayload); + Assertions.assertTrue(validated); + } + + @Then("the header of the event {string} with the status {string} contains a valid signature") + public void validateHeader(String _unused, String status) { + + WebhooksHelper.Response response = null; + if (status.equals("Delivered")) { + response = deliveryReportRecipientDelivered; + } else if (status.equals("Aborted")) { + response = deliveryReportRecipientAborted; + } + + boolean validated = + service.validateAuthenticationHeader(SECRET, response.headers, response.rawPayload); + Assertions.assertTrue(validated); + } } From f7fea5b696132d6ce908a0bb9ac15e0e9e7e5b4b Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 14 Jan 2025 16:38:31 +0100 Subject: [PATCH 50/65] refactor (SMS/Group): Remove readOnly fields from request declaration --- .../v1/groups/request/GroupRequest.java | 40 ------------------- 1 file changed, 40 deletions(-) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java index 102c51329..080b68c6a 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupRequest.java @@ -95,16 +95,6 @@ static Builder builder() { /** Dedicated Builder */ interface Builder { - /** - * see getter - * - * @param id see getter - * @return Current builder - * @see #getId - * @readOnly This field is returned by the server and cannot be modified - */ - Builder setId(String id); - /** * see getter * @@ -114,36 +104,6 @@ interface Builder { */ Builder setName(String name); - /** - * see getter - * - * @param size see getter - * @return Current builder - * @see #getSize - * @readOnly This field is returned by the server and cannot be modified - */ - Builder setSize(Integer size); - - /** - * see getter - * - * @param createdAt see getter - * @return Current builder - * @see #getCreatedAt - * @readOnly This field is returned by the server and cannot be modified - */ - Builder setCreatedAt(Instant createdAt); - - /** - * see getter - * - * @param modifiedAt see getter - * @return Current builder - * @see #getModifiedAt - * @readOnly This field is returned by the server and cannot be modified - */ - Builder setModifiedAt(Instant modifiedAt); - /** * see getter * From 99dea7d1f07a1c3a18382dd04901d543dc969e5f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 14 Jan 2025 17:56:45 +0100 Subject: [PATCH 51/65] test (SMS/Groups): Unit tests updated --- .../sms/adapters/GroupsServiceTest.java | 18 ++++++------------ .../converters/GroupsDtoConverterTest.java | 8 ++++---- .../sms/api/v1/adapters/GroupsServiceTest.java | 12 ++++++------ .../request/GroupUpdateRequestDtoTest.java | 8 ++++---- .../groups/request/GroupUpdateRequestDto.json | 10 +++++----- .../response/ListGroupsResponseDtoPage0.json | 6 +++--- .../response/ListGroupsResponseDtoPage1.json | 6 +++--- 7 files changed, 31 insertions(+), 37 deletions(-) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java index 2d0baae11..41ed9aac2 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/GroupsServiceTest.java @@ -121,14 +121,11 @@ void list() throws ApiException { .setAutoUpdate( GroupAutoUpdate.builder() .setTo("15551231234") - .setAdd( - GroupAutoUpdateKeyword.builder() - .setFirstWord("Add 1st keyword") - .build()) + .setAdd(GroupAutoUpdateKeyword.builder().setFirstWord("1stKeyword").build()) .setRemove( GroupAutoUpdateKeyword.builder() - .setFirstWord("remove 1st keyword") - .setSecondWord("remove 2nd keyword") + .setFirstWord("1stKeyword") + .setSecondWord("2ndKeyword") .build()) .build()) .build()); @@ -155,14 +152,11 @@ void list() throws ApiException { .setAutoUpdate( GroupAutoUpdate.builder() .setTo("15551231234") - .setAdd( - GroupAutoUpdateKeyword.builder() - .setFirstWord("Add 1st keyword") - .build()) + .setAdd(GroupAutoUpdateKeyword.builder().setFirstWord("1stKeyword").build()) .setRemove( GroupAutoUpdateKeyword.builder() - .setFirstWord("remove 1st keyword") - .setSecondWord("remove 2nd keyword") + .setFirstWord("1stKeyword") + .setSecondWord("2ndKeyword") .build()) .build()) .build()); diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java index 3448fd607..047c233f6 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/adapters/converters/GroupsDtoConverterTest.java @@ -105,10 +105,10 @@ void convertUpdateRequestParameters() throws UnexpectedException { GroupUpdateRequestParameters client = GroupUpdateRequestParameters.builder() .setName("My new customers") - .setAdd(Collections.singletonList("foo")) - .setRemove(Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) - .setAddFromGroup("add from group string") - .setRemoveFromGroup("remove from group string") + .setAdd(Collections.singletonList("+12345674890")) + .setRemove(Arrays.asList("+0987654321", "+3456789123")) + .setAddFromGroup("01FC66621XXXXX119Z8PMV1AHY") + .setRemoveFromGroup("01FC66621XXXXX119Z8PMV1A00") .setAutoUpdate( GroupAutoUpdateRequestParameters.builder() .setTo("15551231234") diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java index a24bec812..b497d8e77 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java @@ -115,11 +115,11 @@ void list() throws ApiException { .setAutoUpdate( GroupAutoUpdate.builder() .setTo("15551231234") - .setAdd(AddKeyword.builder().setFirstWord("Add 1st keyword").build()) + .setAdd(AddKeyword.builder().setFirstWord("1stKeyword").build()) .setRemove( RemoveKeyword.builder() - .setFirstWord("remove 1st keyword") - .setSecondWord("remove 2nd keyword") + .setFirstWord("1stKeyword") + .setSecondWord("2ndKeyword") .build()) .build()) .setChildGroups( @@ -144,11 +144,11 @@ void list() throws ApiException { .setAutoUpdate( GroupAutoUpdate.builder() .setTo("15551231234") - .setAdd(AddKeyword.builder().setFirstWord("Add 1st keyword").build()) + .setAdd(AddKeyword.builder().setFirstWord("1stKeyword").build()) .setRemove( RemoveKeyword.builder() - .setFirstWord("remove 1st keyword") - .setSecondWord("remove 2nd keyword") + .setFirstWord("1stKeyword") + .setSecondWord("2ndKeyword") .build()) .build()) .setChildGroups( diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java index ab1fc4d76..73a215cef 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java @@ -21,10 +21,10 @@ void serialize() throws JsonProcessingException, JSONException { GroupUpdateRequest requestDTO = GroupUpdateRequest.builder() .setName("My new customers") - .setAdd(Arrays.asList("foo")) - .setRemove(Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00")) - .setAddFromGroup("add from group string") - .setRemoveFromGroup("remove from group string") + .setAdd(Arrays.asList("+12345674890")) + .setRemove(Arrays.asList("+0987654321", "+3456789123")) + .setAddFromGroup("01FC66621XXXXX119Z8PMV1AHY") + .setRemoveFromGroup("01FC66621XXXXX119Z8PMV1A00") .setAutoUpdate(GroupDtoTest.groupResponse.getAutoUpdate()) .build(); diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json index 0a95cab1b..660d0da3d 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/groups/request/GroupUpdateRequestDto.json @@ -1,14 +1,14 @@ { "name": "My new customers", "add": [ - "foo" + "+12345674890" ], "remove": [ - "01FC66621XXXXX119Z8PMV1AHY", - "01FC66621XXXXX119Z8PMV1A00" + "+0987654321", + "+3456789123" ], - "add_from_group": "add from group string", - "remove_from_group": "remove from group string", + "add_from_group": "01FC66621XXXXX119Z8PMV1AHY", + "remove_from_group": "01FC66621XXXXX119Z8PMV1A00", "auto_update": { "to": "15551231234", "add": { diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json index a3944d6e5..af9592d88 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json @@ -16,11 +16,11 @@ "auto_update": { "to": 15551231234, "add": { - "first_word": "Add 1st keyword" + "first_word": "1stKeyword" }, "remove": { - "first_word": "remove 1st keyword", - "second_word": "remove 2nd keyword" + "first_word": "1stKeyword", + "second_word": "2ndKeyword" } } }, diff --git a/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json index 73a385add..dab354187 100644 --- a/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json +++ b/openapi-contracts/src/test/resources/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json @@ -16,11 +16,11 @@ "auto_update": { "to": 15551231234, "add": { - "first_word": "Add 1st keyword" + "first_word": "1stKeyword" }, "remove": { - "first_word": "remove 1st keyword", - "second_word": "remove 2nd keyword" + "first_word": "1stKeyword", + "second_word": "2ndKeyword" } } } From de0f702b4f13c4a1d1c8697397b08998d71f5cee Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 14 Jan 2025 17:59:13 +0100 Subject: [PATCH 52/65] test (SMS/Groups): Unit tests updated --- .../sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java index b497d8e77..a49f244d8 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java @@ -81,9 +81,10 @@ void get() throws ApiException { @Test void create() throws ApiException { - when(api.createGroup(eq(null))).thenReturn(groupResponseDto); + when(api.createGroup(eq(GroupRequest.builder().setName("foo").build()))) + .thenReturn(groupResponseDto); - Group response = service.create(null); + Group response = service.create(GroupRequest.builder().setName("foo").build()); TestHelpers.recursiveEquals(response, groupResponseDto); } From 30c224fa9076610c118c72933d8bfded1aeceaa1 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 15 Jan 2025 18:54:15 +0100 Subject: [PATCH 53/65] refactor (SMS): Use auto generated sources for auto-paginated reponse classes --- .../batches/response/ListBatchesResponse.java | 17 +++++++++++++++-- .../response/ListDeliveryReportsResponse.java | 18 +++++++++++++++--- .../v1/groups/response/ListGroupsResponse.java | 15 ++++++++++++++- .../response/ListInboundsResponse.java | 18 +++++++++++++++--- 4 files changed, 59 insertions(+), 9 deletions(-) rename {client => openapi-contracts}/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java (81%) rename {client => openapi-contracts}/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java (82%) rename {client => openapi-contracts}/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java (84%) rename {client => openapi-contracts}/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java (82%) diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java similarity index 81% rename from client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java index 1a99f689b..13a9a313e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/ListBatchesResponse.java @@ -1,3 +1,13 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + package com.sinch.sdk.domains.sms.models.v1.batches.response; import com.sinch.sdk.core.models.pagination.ListResponse; @@ -7,6 +17,7 @@ import java.util.Collection; import java.util.NoSuchElementException; +/** Auto paginated response for list of BatchResponse */ public class ListBatchesResponse extends ListResponse { private final Page page; @@ -19,8 +30,8 @@ public ListBatchesResponse( this.page = page; } + @Override public boolean hasNextPage() { - if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { return false; } @@ -33,6 +44,7 @@ public boolean hasNextPage() { return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); } + @Override public ListBatchesResponse nextPage() { if (!hasNextPage()) { @@ -44,12 +56,13 @@ public ListBatchesResponse nextPage() { return response; } + @Override public Collection getContent() { return page.getEntities(); } @Override public String toString() { - return "ListBatchesResponse{" + "page=" + page + '}'; + return "ListBatchesResponse {" + "page=" + page + '}'; } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java similarity index 82% rename from client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java index d0c18aa32..cabaef578 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/ListDeliveryReportsResponse.java @@ -1,3 +1,13 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + package com.sinch.sdk.domains.sms.models.v1.deliveryreports.response; import com.sinch.sdk.core.models.pagination.ListResponse; @@ -8,6 +18,7 @@ import java.util.Collection; import java.util.NoSuchElementException; +/** Auto paginated response for list of RecipientDeliveryReport */ public class ListDeliveryReportsResponse extends ListResponse { private final Page page; @@ -21,12 +32,11 @@ public ListDeliveryReportsResponse( this.page = page; } + @Override public boolean hasNextPage() { - if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { return false; } - if (null == nextPage) { ListDeliveryReportsQueryParameters.Builder newParameters = ListDeliveryReportsQueryParameters.builder(page.getParameters()); @@ -36,6 +46,7 @@ public boolean hasNextPage() { return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); } + @Override public ListDeliveryReportsResponse nextPage() { if (!hasNextPage()) { @@ -47,12 +58,13 @@ public ListDeliveryReportsResponse nextPage() { return response; } + @Override public Collection getContent() { return page.getEntities(); } @Override public String toString() { - return "RecipientDeliveryReport{" + "page=" + page + '}'; + return "ListDeliveryReportsResponse {" + "page=" + page + '}'; } } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java similarity index 84% rename from client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java index 3a32691c5..79e5dad9c 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/ListGroupsResponse.java @@ -1,3 +1,13 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + package com.sinch.sdk.domains.sms.models.v1.groups.response; import com.sinch.sdk.core.models.pagination.ListResponse; @@ -8,6 +18,7 @@ import java.util.Collection; import java.util.NoSuchElementException; +/** Auto paginated response for list of Group */ public class ListGroupsResponse extends ListResponse { private final Page page; @@ -20,8 +31,8 @@ public ListGroupsResponse( this.page = page; } + @Override public boolean hasNextPage() { - if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { return false; } @@ -34,6 +45,7 @@ public boolean hasNextPage() { return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); } + @Override public ListGroupsResponse nextPage() { if (!hasNextPage()) { @@ -45,6 +57,7 @@ public ListGroupsResponse nextPage() { return response; } + @Override public Collection getContent() { return page.getEntities(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java similarity index 82% rename from client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java index 5aac7b2f9..d51315551 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/ListInboundsResponse.java @@ -1,3 +1,13 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + package com.sinch.sdk.domains.sms.models.v1.inbounds.response; import com.sinch.sdk.core.models.pagination.ListResponse; @@ -8,6 +18,7 @@ import java.util.Collection; import java.util.NoSuchElementException; +/** Auto paginated response for list of InboundMessage */ public class ListInboundsResponse extends ListResponse { private final Page page; @@ -21,12 +32,11 @@ public ListInboundsResponse( this.page = page; } + @Override public boolean hasNextPage() { - if (null == page.getNextPageToken() || null == getContent() || getContent().isEmpty()) { return false; } - if (null == nextPage) { ListInboundMessagesQueryParameters.Builder newParameters = ListInboundMessagesQueryParameters.builder(page.getParameters()); @@ -36,6 +46,7 @@ public boolean hasNextPage() { return (null != nextPage.getContent() && !nextPage.getContent().isEmpty()); } + @Override public ListInboundsResponse nextPage() { if (!hasNextPage()) { @@ -47,12 +58,13 @@ public ListInboundsResponse nextPage() { return response; } + @Override public Collection getContent() { return page.getEntities(); } @Override public String toString() { - return "ListInboundsResponse{" + "page=" + page + '}'; + return "ListInboundsResponse {" + "page=" + page + '}'; } } From f6c1862e80b22eec292175bfde0d9c5c88f01801 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 17 Jan 2025 11:15:57 +0100 Subject: [PATCH 54/65] feat (SMS): Remove service adaptors layer and use generated services --- .../domains/sms/api/v1/BatchesService.java | 31 - .../sms/api/v1/DeliveryReportsService.java | 23 - .../sdk/domains/sms/api/v1/GroupsService.java | 126 --- .../domains/sms/api/v1/InboundsService.java | 13 - .../sms/api/v1/adapters/BatchesService.java | 77 -- .../v1/adapters/DeliveryReportsService.java | 69 -- .../sms/api/v1/adapters/GroupsService.java | 76 -- .../sms/api/v1/adapters/InboundsService.java | 50 -- .../sms/api/v1/adapters/SMSService.java | 22 +- .../sdk/domains/PaginationFillerHelper.java | 29 + .../api/v1/adapters/BatchesServiceTest.java | 776 +++++++++--------- .../adapters/DeliveryReportsServiceTest.java | 359 ++++---- .../api/v1/adapters/GroupsServiceTest.java | 393 ++++++--- .../api/v1/adapters/InboundsServiceTest.java | 285 ++++--- .../sms/api/v1/internal/BatchesApiTest.java | 332 -------- .../sms/api/v1/internal/InboundsApiTest.java | 141 ---- .../com/sinch/sdk/core/http/HttpMapper.java | 9 + .../sinch/sdk/core/http/HttpRequestTest.java | 6 +- .../request/GroupUpdateRequestDtoTest.java | 22 +- 19 files changed, 1119 insertions(+), 1720 deletions(-) delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java delete mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java create mode 100644 client/src/test/java/com/sinch/sdk/domains/PaginationFillerHelper.java delete mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java delete mode 100644 client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java deleted file mode 100644 index 0d917bfb9..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; - -public interface BatchesService { - - BatchResponse send(BatchRequest batch) throws ApiException; - - ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException; - - DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch); - - BatchResponse get(String batchId) throws ApiException; - - BatchResponse replace(String batchId, BatchRequest batch) throws ApiException; - - BatchResponse cancel(String batchId) throws ApiException; - - void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest recipients) - throws ApiException; - - BatchResponse update(String batchId, UpdateBatchRequest request) throws ApiException; -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java deleted file mode 100644 index a8a909c17..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; - -public interface DeliveryReportsService { - - BatchDeliveryReport get(String batchId) throws ApiException; - - BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters parameters) - throws ApiException; - - RecipientDeliveryReport getForNumber(String batchId, String recipient) throws ApiException; - - ListDeliveryReportsResponse list() throws ApiException; - - ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters parameters) - throws ApiException; -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java deleted file mode 100644 index 5733cd916..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java +++ /dev/null @@ -1,126 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.domains.sms.models.v1.groups.Group; -import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; -import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; -import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; -import java.util.Collection; - -/** - * Groups Service - * - *

A group is a set of phone numbers (or MSISDNs) that can be used as a target when sending an - * SMS. An phone number (MSISDN) can only occur once in a group and any attempts to add a duplicate - * are ignored but not rejected. - * - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups - * @since 1.0 - */ -public interface GroupsService { - - /** - * Retrieve a group. - * - *

This operation retrieves a specific group with the provided group ID. - * - * @param groupId The inbound ID found when listing inbound messages - * @return Group associated to groupId - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/RetrieveGroup - * @since 1.0 - */ - Group get(String groupId) throws ApiException; - - /** - * Create a group. - * - *

A group is a set of phone numbers (MSISDNs) that can be used as a target in the - * send_batch_msg operation. An MSISDN can only occur once in a group and any attempts to - * add a duplicate would be ignored but not rejected. - * - * @param parameters Parameters to be used to define group onto creation - * @return Created group - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/CreateGroup - * @since 1.0 - */ - Group create(GroupRequest parameters) throws ApiException; - - /** - * Replace a group - * - *

The replace operation will replace all parameters, including members, of an existing group - * with new values. - * - *

Replacing a group targeted by a batch message scheduled in the future is allowed and changes - * will be reflected when the batch is sent. - * - * @param groupId ID of a group that you are interested in getting. - * @param parameters Parameters to be replaced for group - * @return Group associated to groupId - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ReplaceGroup - * @since 1.0 - */ - Group replace(String groupId, GroupRequest parameters) throws ApiException; - - /** - * Update a group - * - * @param groupId ID of a group that you are interested in getting. - * @param parameters Parameters to be used to update group - * @return Modified group associated to groupId - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/UpdateGroup - * @since 1.0 - */ - Group update(String groupId, GroupUpdateRequest parameters) throws ApiException; - - /** - * Delete a group - * - * @param groupId ID of a group that you are interested in getting. - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup - * @since 1.0 - */ - void delete(String groupId) throws ApiException; - - /** - * Get phone numbers for a group - * - * @param groupId ID of a group that you are interested in getting. - * @return A list of phone numbers in E.164 format. - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/deleteGroup - * @since 1.0 - */ - Collection listMembers(String groupId) throws ApiException; - - /** - * List Groups - * - *

With the list operation you can list all groups that you have created. This operation - * supports pagination. - * - *

Groups are returned in reverse chronological order. - * - * @param parameters Filtering parameters - * @return group list - * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Groups/#tag/Groups/operation/ListGroups - * @since 1.0 - */ - ListGroupsResponse list(ListGroupsQueryParameters parameters) throws ApiException; - - /** - * List groups with default parameters - * - * @return See {@link #list(ListGroupsQueryParameters)} - * @since 1.0 - */ - ListGroupsResponse list() throws ApiException; -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java deleted file mode 100644 index 4861622b2..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; -import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; - -public interface InboundsService { - - ListInboundsResponse list(ListInboundMessagesQueryParameters parameters) throws ApiException; - - InboundMessage get(String inboundId) throws ApiException; -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java deleted file mode 100644 index 76879511f..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesService.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1.adapters; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.AuthManager; -import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.core.http.HttpMapper; -import com.sinch.sdk.core.models.pagination.Page; -import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; -import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; -import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; -import com.sinch.sdk.models.SmsContext; -import java.util.Map; - -public class BatchesService implements com.sinch.sdk.domains.sms.api.v1.BatchesService { - - private final BatchesApi api; - - public BatchesService( - String uriUUID, - SmsContext context, - HttpClient httpClient, - Map authManagers) { - this.api = - new BatchesApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); - } - - protected BatchesApi getApi() { - return this.api; - } - - public BatchResponse send(BatchRequest batch) throws ApiException { - return getApi().send(batch); - } - - public ListBatchesResponse list(ListBatchesQueryParameters parameters) throws ApiException { - - ApiBatchList response = getApi().list(parameters); - - SMSCursorPageNavigator navigator = - new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); - - return new ListBatchesResponse(this, new Page<>(parameters, response.getBatches(), navigator)); - } - - public DryRunResponse dryRun(DryRunQueryParameters queryParameters, BatchRequest batch) { - return getApi().dryRun(queryParameters, batch); - } - - public BatchResponse get(String batchId) throws ApiException { - return getApi().get(batchId); - } - - public BatchResponse replace(String batchId, BatchRequest batch) throws ApiException { - return getApi().replace(batchId, batch); - } - - public BatchResponse cancel(String batchId) throws ApiException { - return getApi().cancel(batchId); - } - - public void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest request) - throws ApiException { - getApi().sendDeliveryFeedback(batchId, request); - } - - public BatchResponse update(String batchId, UpdateBatchRequest request) throws ApiException { - return getApi().update(batchId, request); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java deleted file mode 100644 index bac9bd64b..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsService.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1.adapters; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.AuthManager; -import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.core.http.HttpMapper; -import com.sinch.sdk.core.models.pagination.Page; -import com.sinch.sdk.domains.sms.api.v1.internal.DeliveryReportsApi; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal.DeliveryReportList; -import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; -import com.sinch.sdk.models.SmsContext; -import java.util.Map; - -public class DeliveryReportsService - implements com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService { - - private final DeliveryReportsApi api; - - protected DeliveryReportsApi getApi() { - return this.api; - } - - public DeliveryReportsService( - String uriUUID, - SmsContext context, - HttpClient httpClient, - Map authManagers) { - this.api = - new DeliveryReportsApi( - httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); - } - - public BatchDeliveryReport get(String batchId) throws ApiException { - - return getApi().get(batchId); - } - - public BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters parameters) - throws ApiException { - - return getApi().get(batchId, parameters); - } - - public RecipientDeliveryReport getForNumber(String batchId, String recipient) - throws ApiException { - return getApi().getForNumber(batchId, recipient); - } - - public ListDeliveryReportsResponse list() throws ApiException { - return this.list(null); - } - - public ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters parameters) - throws ApiException { - - DeliveryReportList response = getApi().list(parameters); - - SMSCursorPageNavigator navigator = - new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); - - return new ListDeliveryReportsResponse( - this, new Page<>(parameters, response.getDeliveryReports(), navigator)); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java deleted file mode 100644 index 72a78b9c5..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsService.java +++ /dev/null @@ -1,76 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1.adapters; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.AuthManager; -import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.core.http.HttpMapper; -import com.sinch.sdk.core.models.pagination.Page; -import com.sinch.sdk.domains.sms.api.v1.internal.GroupsApi; -import com.sinch.sdk.domains.sms.models.v1.groups.Group; -import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; -import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; -import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; -import com.sinch.sdk.domains.sms.models.v1.groups.response.internal.ApiGroupList; -import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; -import com.sinch.sdk.models.SmsContext; -import java.util.Collection; -import java.util.Map; - -public class GroupsService implements com.sinch.sdk.domains.sms.api.v1.GroupsService { - - private final GroupsApi api; - - protected GroupsApi getApi() { - return this.api; - } - - public GroupsService( - String uriUUID, - SmsContext context, - HttpClient httpClient, - Map authManagers) { - this.api = - new GroupsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); - } - - public Group get(String groupId) throws ApiException { - - return getApi().retrieveGroup(groupId); - } - - public Group create(GroupRequest parameters) throws ApiException { - - return getApi().createGroup(parameters); - } - - public Group replace(String groupId, GroupRequest parameters) throws ApiException { - - return getApi().replaceGroup(groupId, parameters); - } - - public Group update(String groupId, GroupUpdateRequest parameters) throws ApiException { - return getApi().updateGroup(groupId, parameters); - } - - public void delete(String groupId) throws ApiException { - getApi().deleteGroup(groupId); - } - - public Collection listMembers(String groupId) throws ApiException { - return getApi().getMembers(groupId); - } - - public ListGroupsResponse list(ListGroupsQueryParameters parameters) throws ApiException { - ApiGroupList response = getApi().listGroups(parameters); - - SMSCursorPageNavigator navigator = - new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); - - return new ListGroupsResponse(this, new Page<>(parameters, response.getGroups(), navigator)); - } - - public ListGroupsResponse list() throws ApiException { - return list(null); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java deleted file mode 100644 index 4fae304ca..000000000 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsService.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1.adapters; - -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.AuthManager; -import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.core.http.HttpMapper; -import com.sinch.sdk.core.models.pagination.Page; -import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; -import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; -import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; -import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; -import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; -import com.sinch.sdk.models.SmsContext; -import java.util.Map; - -public class InboundsService implements com.sinch.sdk.domains.sms.api.v1.InboundsService { - - private final InboundsApi api; - - public InboundsService( - String uriUUID, - SmsContext context, - HttpClient httpClient, - Map authManagers) { - this.api = - new InboundsApi( - httpClient, context.getSmsServer(), authManagers, new HttpMapper(), uriUUID); - } - - protected InboundsApi getApi() { - return this.api; - } - - public ListInboundsResponse list(ListInboundMessagesQueryParameters parameters) - throws ApiException { - - ApiInboundList response = getApi().list(parameters); - - SMSCursorPageNavigator navigator = - new SMSCursorPageNavigator(response.getPage(), response.getPageSize()); - - return new ListInboundsResponse( - this, new Page<>(parameters, response.getInbounds(), navigator)); - } - - public InboundMessage get(String inboundId) throws ApiException { - return getApi().get(inboundId); - } -} diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java index de0e2465f..1650c4e51 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/SMSService.java @@ -8,6 +8,10 @@ import com.sinch.sdk.core.http.HttpMapper; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.core.utils.StringUtil; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; +import com.sinch.sdk.domains.sms.api.v1.InboundsService; import com.sinch.sdk.models.SmsContext; import com.sinch.sdk.models.SmsServicePlanCredentials; import com.sinch.sdk.models.UnifiedCredentials; @@ -50,7 +54,7 @@ public SMSService( LOGGER.fine("Activate SMS API with server='" + context.getSmsServer().getUrl() + "'"); OAuthManager oAuthManager = - new OAuthManager(credentials, oAuthServer, new HttpMapper(), httpClient); + new OAuthManager(credentials, oAuthServer, HttpMapper.getInstance(), httpClient); this.uriUUID = credentials.getProjectId(); this.context = context; @@ -87,7 +91,9 @@ public SMSService( @Override public BatchesService batches() { if (null == this.batches) { - this.batches = new BatchesService(uriUUID, context, httpClient, authManagers); + this.batches = + new BatchesServiceImpl( + httpClient, context.getSmsServer(), authManagers, HttpMapper.getInstance(), uriUUID); } return this.batches; } @@ -95,7 +101,9 @@ public BatchesService batches() { @Override public InboundsService inbounds() { if (null == this.inbounds) { - this.inbounds = new InboundsService(uriUUID, context, httpClient, authManagers); + this.inbounds = + new InboundsServiceImpl( + httpClient, context.getSmsServer(), authManagers, HttpMapper.getInstance(), uriUUID); } return this.inbounds; } @@ -103,7 +111,9 @@ public InboundsService inbounds() { @Override public DeliveryReportsService deliveryReports() { if (null == this.deliveryReports) { - this.deliveryReports = new DeliveryReportsService(uriUUID, context, httpClient, authManagers); + this.deliveryReports = + new DeliveryReportsServiceImpl( + httpClient, context.getSmsServer(), authManagers, HttpMapper.getInstance(), uriUUID); } return this.deliveryReports; } @@ -111,7 +121,9 @@ public DeliveryReportsService deliveryReports() { @Override public GroupsService groups() { if (null == this.groups) { - this.groups = new GroupsService(uriUUID, context, httpClient, authManagers); + this.groups = + new GroupsServiceImpl( + httpClient, context.getSmsServer(), authManagers, HttpMapper.getInstance(), uriUUID); } return this.groups; } diff --git a/client/src/test/java/com/sinch/sdk/domains/PaginationFillerHelper.java b/client/src/test/java/com/sinch/sdk/domains/PaginationFillerHelper.java new file mode 100644 index 000000000..aec8749f6 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/PaginationFillerHelper.java @@ -0,0 +1,29 @@ +package com.sinch.sdk.domains; + +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +public class PaginationFillerHelper { + + public static Collection parametersFiller( + String name, Object value, STYLE style, boolean explode, List values) { + + List parameters = new ArrayList<>(); + + URLParameter parameter = new URLParameter(name, value, style, explode); + parameters.add(parameter); + for (int i = 0; i < values.size(); ) { + parameter = + new URLParameter( + (String) values.get(i++), + values.get(i++), + (STYLE) values.get(i++), + (boolean) values.get(i++)); + parameters.add(parameter); + } + return parameters; + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java index 1cc3825c3..be89d7e97 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java @@ -1,349 +1,186 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.sms.api.v1.internal.BatchesApi; -import com.sinch.sdk.domains.sms.models.v1.batches.DeliveryReportType; -import com.sinch.sdk.domains.sms.models.v1.batches.MediaBody; -import com.sinch.sdk.domains.sms.models.v1.batches.MediaBodyDtoTest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.BinaryRequest; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.PaginationFillerHelper; +import com.sinch.sdk.domains.sms.api.v1.BatchesService; import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.MediaRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBinaryRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateMediaRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BinaryResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.MediaResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.TextResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; -import com.sinch.sdk.models.SmsContext; import java.time.Instant; -import java.util.AbstractMap; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; @TestWithResources public class BatchesServiceTest extends BaseTest { - static final String id = "01FC66621XXXXX119Z8PMV1QPQ"; - static final List to = Arrays.asList("+15551231234", "+15551256344"); - static final String from = "+15551231234"; - static final boolean canceled = false; - static final Instant createdAt = Instant.parse("2019-08-24T14:15:22Z"); - static final Instant modifiedAt = Instant.parse("2019-08-24T14:17:22Z"); - static final DeliveryReportType deliveryReport = DeliveryReportType.NONE; - static final Instant sendAt = Instant.parse("2019-08-24T14:19:22Z"); - static final Instant expireAt = Instant.parse("2019-08-24T14:21:22Z"); - static final String callbackUrl = "callback url"; - static final String clientReference = "myReference"; - static final boolean flashMessage = true; - static final boolean feedbackEnabled = false; - static final boolean truncateConcat = true; - static final int maxNumberOfMessageParts = 1; - static final int fromTon = 6; - static final int fromNpi = 18; - static final String udh = "foo udh"; - static final String body = "Hi ${name} ({an identifier}) ! How are you?"; - public static final BinaryResponse batchBinary = - BinaryResponse.builder() - .setId(id) - .setTo(to) - .setFrom(from) - .setCanceled(canceled) - .setBody(body) - .setCreatedAt(createdAt) - .setModifiedAt(modifiedAt) - .setDeliveryReport(deliveryReport) - .setSendAt(sendAt) - .setExpireAt(expireAt) - .setCallbackUrl(callbackUrl) - .setClientReference(clientReference) - .setFeedbackEnabled(feedbackEnabled) - .setFromTon(fromTon) - .setFromNpi(fromNpi) - .setUdh(udh) - .build(); - - static final Map anIdentifierParameters = - Stream.of( - new AbstractMap.SimpleEntry<>("15551231234", "an identifier value for 15551231234"), - new AbstractMap.SimpleEntry<>("15551256344", "an identifier value for 15551256344")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - static final Map nameParameters = - Stream.of( - new AbstractMap.SimpleEntry<>("15551231234", "name value for 15551231234"), - new AbstractMap.SimpleEntry<>("15551256344", "name value for 15551256344"), - new AbstractMap.SimpleEntry<>("default", "default value")) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - static final Map> parameters = - Stream.of( - new AbstractMap.SimpleEntry<>("name", nameParameters), - new AbstractMap.SimpleEntry<>("an identifier", anIdentifierParameters)) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - public static final MediaResponse batchMedia = - MediaResponse.builder() - .setId(id) - .setTo(to) - .setFrom(from) - .setCanceled(canceled) - .setBody( - MediaBody.builder() - .setSubject("subject field") - .setUrl( - "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .setMessage("Hi ${name} ({an identifier}) ! How are you?") - .build()) - .setCreatedAt(Instant.parse("2019-08-24T14:14:22Z")) - .setModifiedAt(Instant.parse("2019-08-24T14:15:22Z")) - .setDeliveryReport(DeliveryReportType.SUMMARY) - .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) - .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) - .setCallbackUrl(callbackUrl) - .setClientReference("client reference") - .setFeedbackEnabled(feedbackEnabled) - .setStrictValidation(true) - .setParameters(parameters) - .build(); - public static final TextResponse batchText = - TextResponse.builder() - .setId(id) - .setTo(to) - .setFrom(from) - .setCanceled(canceled) - .setBody(body) - .setCreatedAt(createdAt) - .setModifiedAt(modifiedAt) - .setDeliveryReport(deliveryReport) - .setSendAt(sendAt) - .setExpireAt(expireAt) - .setCallbackUrl(callbackUrl) - .setClientReference(clientReference) - .setFlashMessage(flashMessage) - .setFeedbackEnabled(feedbackEnabled) - .setTruncateConcat(truncateConcat) - .setMaxNumberOfMessageParts(maxNumberOfMessageParts) - .setFromTon(fromTon) - .setFromNpi(fromNpi) - .setParameters(parameters) - .build(); - - public static final BinaryRequest sendSmsBatchBinaryRequest = - BinaryRequest.builder() - .setTo(to) - .setFrom(from) - .setBody(body) - .setDeliveryReport(deliveryReport) - .setSendAt(sendAt) - .setExpireAt(expireAt) - .setCallbackUrl(callbackUrl) - .setClientReference(clientReference) - .setFeedbackEnabled(feedbackEnabled) - .setFromTon(fromTon) - .setFromNpi(fromNpi) - .setUdh(udh) - .build(); - - public static final MediaRequest sendSmsBatchMediaRequest = - MediaRequest.builder() - .setTo(to) - .setFrom(from) - .setBody( - MediaBody.builder() - .setUrl( - "https://en.wikipedia.org/wiki/Sinch_(company)#/media/File:Sinch_LockUp_RGB.png") - .setMessage("Hi ${name} ({an identifier}) ! How are you?") - .build()) - .setDeliveryReport(DeliveryReportType.SUMMARY) - .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) - .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) - .setCallbackUrl(callbackUrl) - .setClientReference("client reference") - .setFeedbackEnabled(feedbackEnabled) - .setStrictValidation(true) - .setParameters(parameters) - .build(); - public static final TextRequest sendSmsBatchTextRequest = - TextRequest.builder() - .setTo(to) - .setFrom(from) - .setBody(body) - .setDeliveryReport(deliveryReport) - .setSendAt(sendAt) - .setExpireAt(expireAt) - .setCallbackUrl(callbackUrl) - .setClientReference(clientReference) - .setFlashMessage(flashMessage) - .setFeedbackEnabled(feedbackEnabled) - .setTruncateConcat(truncateConcat) - .setMaxNumberOfMessageParts(maxNumberOfMessageParts) - .setFromTon(fromTon) - .setFromNpi(fromNpi) - .setParameters(parameters) - .build(); - - public static final UpdateTextRequest updateSmsBatchTextRequest = - UpdateTextRequest.builder() - .setToAdd(to) - .setFrom(from) - .setBody(body) - .setDeliveryReport(deliveryReport) - .setSendAt(sendAt) - .setExpireAt(expireAt) - .setCallbackUrl(callbackUrl) - .setParameters(parameters) - .build(); - - public static final UpdateMediaRequest updateSmsBatchMediaRequest = - UpdateMediaRequest.builder() - .setToRemove(to) - .setFrom(from) - .setBody(MediaBodyDtoTest.mediaBodyDto) - .setDeliveryReport(DeliveryReportType.SUMMARY) - .setSendAt(Instant.parse("2019-08-24T14:16:22Z")) - .setExpireAt(Instant.parse("2019-08-24T14:17:22Z")) - .setCallbackUrl(callbackUrl) - .setStrictValidation(true) - .setParameters(parameters) - .build(); - - public static final UpdateBinaryRequest updateSmsBatchBinaryRequest = - UpdateBinaryRequest.builder() - .setToAdd(Arrays.asList("+15551231234", "+15987365412")) - .setToRemove(Arrays.asList("+0123456789", "+9876543210")) - .setFrom(from) - .setBody(body) - .setDeliveryReport(DeliveryReportType.FULL) - .setSendAt(sendAt) - .setExpireAt(expireAt) - .setCallbackUrl(callbackUrl) - .setUdh(udh) - .build(); - - @GivenJsonResource("/domains/sms/v1/batches/response/BinaryResponseDto.json") - public BatchResponse binaryResponseDto; - - @GivenJsonResource("/domains/sms/v1/batches/response/MediaResponseDto.json") - BatchResponse mediaResponseDto; + static final String SMS_AUTH_NAMES = "BearerAuth"; + + @GivenJsonResource("/domains/sms/v1/batches/request/TextRequestDto.json") + TextRequest textRequestDto; + + @GivenTextResource("/domains/sms/v1/batches/response/TextResponseDto.json") + String jsonTextResponseDto; @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") BatchResponse textResponseDto; + @GivenTextResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") + String jsonDryRunResponseDto; + @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") DryRunResponse dryRunResponseDto; + @GivenTextResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") + String jsonBatchesResponseDtoPage0; + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") ApiBatchList listBatchesResponseDtoPage0; + @GivenTextResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage1.json") + String jsonBatchesResponseDtoPage1; + @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage1.json") ApiBatchList listBatchesResponseDtoPage1; - @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage2.json") - ApiBatchList listBatchesResponseDtoPage2; + @GivenTextResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage2.json") + String jsonBatchesResponseDtoPage2; + + @GivenJsonResource("/domains/sms/v1/batches/request/UpdateTextRequestDto.json") + UpdateTextRequest updateTextRequestDto; + + @GivenJsonResource("/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json") + SendDeliveryFeedbackRequest sendDeliveryFeedbackRequestDto; - @Mock SmsContext context; @Mock HttpClient httpClient; + @Mock ServerConfiguration serverConfiguration; @Mock Map authManagers; - @Mock BatchesApi api; - BatchesService service; - String uriPartID = "foovalue"; - @Captor ArgumentCaptor recipientsCaptor; + BatchesService service; @BeforeEach public void initMocks() { - service = spy(new BatchesService(uriPartID, context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new BatchesServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); } @Test - void getBinary() throws ApiException { - - when(api.get(eq("foo binary batch id"))).thenReturn(binaryResponseDto); + void get() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20binary%20batch%20id", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); BatchResponse response = service.get("foo binary batch id"); - TestHelpers.recursiveEquals(response, batchBinary); - } - - @Test - void getMedia() throws ApiException { - - when(api.get(eq("foo media batch id"))).thenReturn(mediaResponseDto); - - BatchResponse response = service.get("foo media batch id"); - - TestHelpers.recursiveEquals(response, batchMedia); - } - - @Test - void getText() throws ApiException { - - when(api.get(eq("foo text batch id"))).thenReturn(textResponseDto); - - BatchResponse response = service.get("foo text batch id"); - - TestHelpers.recursiveEquals(response, batchText); - } - - @Test - void sendBinary() throws ApiException { - - when(api.send(sendSmsBatchBinaryRequest)).thenReturn(binaryResponseDto); - - BatchResponse response = service.send(sendSmsBatchBinaryRequest); - - TestHelpers.recursiveEquals(response, batchBinary); + TestHelpers.recursiveEquals(response, textResponseDto); } @Test - void sendMedia() throws ApiException { - - when(api.send(sendSmsBatchMediaRequest)).thenReturn(mediaResponseDto); - - BatchResponse response = service.send(sendSmsBatchMediaRequest); - - TestHelpers.recursiveEquals(response, batchMedia); + void send() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.POST, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = service.send(textRequestDto); + + TestHelpers.recursiveEquals(response, textResponseDto); } @Test - void sendText() throws ApiException { - - when(api.send(sendSmsBatchTextRequest)).thenReturn(textResponseDto); + void dryRunDefault() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/dry_run", + HttpMethod.POST, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonDryRunResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + DryRunResponse response = service.dryRun(textRequestDto); - BatchResponse response = service.send(sendSmsBatchTextRequest); - - TestHelpers.recursiveEquals(response, batchText); + TestHelpers.recursiveEquals(response, dryRunResponseDto); } @Test @@ -351,165 +188,294 @@ void dryRun() throws ApiException { DryRunQueryParameters queryParameters = DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(456).build(); - when(api.dryRun(eq(queryParameters), eq(sendSmsBatchTextRequest))) - .thenReturn(dryRunResponseDto); - DryRunResponse response = service.dryRun(queryParameters, sendSmsBatchTextRequest); + Collection urlParameters = + Arrays.asList( + new URLParameter("per_recipient", true, STYLE.FORM, true), + new URLParameter("number_of_recipients", 456, STYLE.FORM, true)); + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/dry_run", + HttpMethod.POST, + urlParameters, + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonDryRunResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + DryRunResponse response = service.dryRun(queryParameters, textRequestDto); TestHelpers.recursiveEquals(response, dryRunResponseDto); } @Test - void list() throws ApiException { - - ListBatchesQueryParameters initialRequest = ListBatchesQueryParameters.builder().build(); - ListBatchesQueryParameters page1 = ListBatchesQueryParameters.builder().setPage(1).build(); - ListBatchesQueryParameters page2 = ListBatchesQueryParameters.builder().setPage(2).build(); - - when(api.list(initialRequest)).thenReturn(listBatchesResponseDtoPage0); - when(api.list(page1)).thenReturn(listBatchesResponseDtoPage1); - when(api.list(page2)).thenReturn(listBatchesResponseDtoPage2); - ListBatchesResponse response = service.list(initialRequest); - - Iterator iterator = response.iterator(); - BatchResponse batch = iterator.next(); - Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - TestHelpers.recursiveEquals( - batch, - BinaryResponse.builder() - .setId("01HEAWCHESCXG8SDG5R10VF8E1") - .setTo(Collections.singletonList("339876543213")) - .setFrom("33123456789") - .setCanceled(false) - .setBody("the body") - .setCreatedAt(Instant.parse("2023-11-03T15:21:21.113Z")) - .setModifiedAt(Instant.parse("2023-11-03T15:21:21.568Z")) - .setDeliveryReport(DeliveryReportType.NONE) - .setExpireAt(Instant.parse("2023-11-06T15:21:21.973Z")) - .setClientReference("a client reference") - .setFeedbackEnabled(false) - .build()); - - batch = iterator.next(); - Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - TestHelpers.recursiveEquals( - batch, - TextResponse.builder() - .setId("01HEAC0AG69SVYYQ675VPYT28Q") - .setTo(Collections.singletonList("3300000000")) - .setCanceled(false) - .setBody("the body") - .setCreatedAt(Instant.parse("2023-11-03T10:35:03.558Z")) - .setModifiedAt(Instant.parse("2023-11-03T10:35:03.666Z")) - .setDeliveryReport(DeliveryReportType.NONE) - .setExpireAt(Instant.parse("2023-11-03T10:35:03.558Z")) - .setFeedbackEnabled(true) - .setFlashMessage(false) - .build()); - - batch = iterator.next(); - Assertions.assertThat(iterator.hasNext()).isEqualTo(false); - TestHelpers.recursiveEquals( - batch, - MediaResponse.builder() - .setId("01HEABZ9S80D4ENE3X6CPMATZR") - .setTo(Collections.singletonList("331111111")) - .setCanceled(false) - .setBody(MediaBody.builder().setUrl("an URL").build()) - .setCreatedAt(Instant.parse("2023-11-03T10:34:30.056Z")) - .setModifiedAt(Instant.parse("2023-11-03T10:34:30.156Z")) - .setDeliveryReport(DeliveryReportType.SUMMARY) - .setExpireAt(Instant.parse("2023-11-06T10:34:30.256Z")) - .setFeedbackEnabled(false) - .build()); - } - - @Test - void updateText() throws ApiException { - - when(api.update(eq("foo text batch id"), eq(updateSmsBatchTextRequest))) - .thenReturn(textResponseDto); - - BatchResponse response = service.update("foo text batch id", updateSmsBatchTextRequest); - - TestHelpers.recursiveEquals(response, batchText); - } - - @Test - void updateMedia() throws ApiException { - - when(api.update(eq("foo text batch id"), eq(updateSmsBatchMediaRequest))) - .thenReturn(mediaResponseDto); - - BatchResponse response = service.update("foo text batch id", updateSmsBatchMediaRequest); - - TestHelpers.recursiveEquals(response, batchMedia); + void listDefault() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonBatchesResponseDtoPage0.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + ListBatchesResponse response = service.list(); + + TestHelpers.recursiveEquals(response.getContent(), listBatchesResponseDtoPage0.getItems()); } @Test - void updateBinary() throws ApiException { + void list() throws ApiException { - when(api.update(eq("foo text batch id"), eq(updateSmsBatchBinaryRequest))) - .thenReturn(binaryResponseDto); + List commonParameters = + Arrays.asList( + "page_size", + 2, + STYLE.FORM, + true, + "from", + "+1234567890", + STYLE.FORM, + true, + "start_date", + "2023-11-03T15:21:21.113Z", + STYLE.FORM, + true, + "end_date", + "2023-12-12T15:54:21.321Z", + STYLE.FORM, + true, + "client_reference", + "client reference", + STYLE.FORM, + true); + + Collection urlParametersPage0 = + PaginationFillerHelper.parametersFiller("page", 0, STYLE.FORM, true, commonParameters); + Collection urlParametersPage1 = + PaginationFillerHelper.parametersFiller("page", 1, STYLE.FORM, true, commonParameters); + Collection urlParametersPage2 = + PaginationFillerHelper.parametersFiller("page", 2, STYLE.FORM, true, commonParameters); + + HttpRequest httpRequest0 = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.GET, + urlParametersPage0, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + + HttpRequest httpRequest1 = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.GET, + urlParametersPage1, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + + HttpRequest httpRequest2 = + new HttpRequest( + "/xms/v1/foovalue/batches", + HttpMethod.GET, + urlParametersPage2, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + + HttpResponse httpResponse0 = + new HttpResponse(200, null, Collections.emptyMap(), jsonBatchesResponseDtoPage0.getBytes()); + HttpResponse httpResponse1 = + new HttpResponse(200, null, Collections.emptyMap(), jsonBatchesResponseDtoPage1.getBytes()); + HttpResponse httpResponse2 = + new HttpResponse(200, null, Collections.emptyMap(), jsonBatchesResponseDtoPage2.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest0)))) + .thenReturn(httpResponse0); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest1)))) + .thenReturn(httpResponse1); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest2)))) + .thenReturn(httpResponse2); + + ListBatchesQueryParameters initialRequest = + ListBatchesQueryParameters.builder() + .setPage(0) + .setPageSize(2) + .setFrom("+1234567890") + .setClientReference("client reference") + .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) + .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) + .build(); - BatchResponse response = service.update("foo text batch id", updateSmsBatchBinaryRequest); + ListBatchesResponse response = service.list(initialRequest); - TestHelpers.recursiveEquals(response, batchBinary); - } + Iterator iterator = response.iterator(); - @Test - void replaceBinary() throws ApiException { + BatchResponse item = iterator.next(); + TestHelpers.recursiveEquals(item, listBatchesResponseDtoPage0.getItems().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - when(api.replace(eq("foo text batch id"), eq(sendSmsBatchBinaryRequest))) - .thenReturn(binaryResponseDto); + item = iterator.next(); + TestHelpers.recursiveEquals(item, listBatchesResponseDtoPage0.getItems().get(1)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - BatchResponse response = service.replace("foo text batch id", sendSmsBatchBinaryRequest); + item = iterator.next(); + TestHelpers.recursiveEquals(item, listBatchesResponseDtoPage1.getItems().get(0)); - TestHelpers.recursiveEquals(response, batchBinary); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); } @Test - void replaceMedia() throws ApiException { - - when(api.replace(eq("foo text batch id"), eq(sendSmsBatchMediaRequest))) - .thenReturn(mediaResponseDto); - - BatchResponse response = service.replace("foo text batch id", sendSmsBatchMediaRequest); - - TestHelpers.recursiveEquals(response, batchMedia); + void update() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + HttpMethod.POST, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), + updateTextRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = service.update("foo text batch id", updateTextRequestDto); + + TestHelpers.recursiveEquals(response, textResponseDto); } @Test - void replaceText() throws ApiException { - - when(api.replace(eq("foo text batch id"), eq(sendSmsBatchTextRequest))) - .thenReturn(textResponseDto); - - BatchResponse response = service.replace("foo text batch id", sendSmsBatchTextRequest); - - TestHelpers.recursiveEquals(response, batchText); + void replace() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + HttpMethod.PUT, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + BatchResponse response = service.replace("foo text batch id", textRequestDto); + + TestHelpers.recursiveEquals(response, textResponseDto); } @Test - void cancelBatch() throws ApiException { - - when(api.cancel(eq("foo text batch id"))).thenReturn(textResponseDto); + void cancel() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + HttpMethod.DELETE, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); BatchResponse response = service.cancel("foo text batch id"); - TestHelpers.recursiveEquals(response, batchText); + TestHelpers.recursiveEquals(response, textResponseDto); } @Test void sendDeliveryFeedback() throws ApiException { - SendDeliveryFeedbackRequest request = - SendDeliveryFeedbackRequest.builder().setRecipients(Arrays.asList("foo", "foo2")).build(); - - service.sendDeliveryFeedback("foo text batch id", request); - - verify(api).sendDeliveryFeedback(eq("foo text batch id"), recipientsCaptor.capture()); - SendDeliveryFeedbackRequest dto = recipientsCaptor.getValue(); - TestHelpers.recursiveEquals(dto, request); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20text%20batch%20id/delivery_feedback", + HttpMethod.POST, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), + sendDeliveryFeedbackRequestDto), + Collections.emptyMap(), + Collections.emptyList(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + service.sendDeliveryFeedback("foo text batch id", sendDeliveryFeedbackRequestDto); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java index ad8f03f2f..d040097c6 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java @@ -1,34 +1,41 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.sms.api.v1.internal.DeliveryReportsApi; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.PaginationFillerHelper; +import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryReceiptErrorCode; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.DeliveryStatus; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.EncodingType; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportMMS; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReportSMS; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.QueryReportType; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal.DeliveryReportList; -import com.sinch.sdk.models.SmsContext; import java.time.Instant; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -37,185 +44,259 @@ @TestWithResources class DeliveryReportsServiceTest extends BaseTest { + static final String SMS_AUTH_NAMES = "BearerAuth"; - @Mock SmsContext context; - @Mock HttpClient httpClient; - @Mock Map authManagers; - - @Mock DeliveryReportsApi api; - DeliveryReportsService service; - String uriPartID = "foovalue"; + @GivenTextResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") + String jsonBatchDeliveryReportSMSDto; @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") - BatchDeliveryReport deliveryReportBatchSMSDto; + BatchDeliveryReport batchDeliveryReportSMSDto; - @GivenJsonResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportMMSDto.json") - BatchDeliveryReport deliveryReportBatchMMSDto; - - @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportSMSDto.json") - RecipientDeliveryReport deliveryReportRecipientSMSDto; + @GivenTextResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") + String jsonRecipientDeliveryReportMMSDto; @GivenJsonResource("/domains/sms/v1/deliveryreports/RecipientDeliveryReportMMSDto.json") - RecipientDeliveryReport deliveryReportRecipientMMSDto; + RecipientDeliveryReport recipientDeliveryReportMMSDto; + + @GivenTextResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage0.json") + String jsonListDeliveryReportResponseDtoPage0; @GivenJsonResource( "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage0.json") DeliveryReportList listDeliveryReportResponseDtoPage0; + @GivenTextResource( + "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage1.json") + String jsonListDeliveryReportResponseDtoPage1; + @GivenJsonResource( "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage1.json") DeliveryReportList listDeliveryReportResponseDtoPage1; - @GivenJsonResource( + @GivenTextResource( "/domains/sms/v1/deliveryreports/response/ListDeliveryReportResponseDtoPage2.json") - DeliveryReportList listDeliveryReportResponseDtoPage2; + String jsonListDeliveryReportResponseDtoPage2; + + @Mock ServerConfiguration serverConfiguration; + @Mock HttpClient httpClient; + @Mock Map authManagers; + + DeliveryReportsService service; @BeforeEach public void initMocks() { - service = spy(new DeliveryReportsService(uriPartID, context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new DeliveryReportsServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); } @Test - void getSimplifiedDeliveryReport() throws ApiException { - - when(api.get(eq("foo binary batch id"))).thenReturn(deliveryReportBatchSMSDto); + void getBatchDeliveryReport() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20binary%20batch%20id/delivery_report", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonBatchDeliveryReportSMSDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); BatchDeliveryReport response = service.get("foo binary batch id"); - TestHelpers.recursiveEquals(response, deliveryReportBatchSMSDto); - } - - @Test - void getBatchDeliveryReportSMS() throws ApiException { - - BatchDeliveryReportQueryParameters queryParameters = - BatchDeliveryReportQueryParameters.builder() - .setCode( - Arrays.asList( - DeliveryReceiptErrorCode.from(456), DeliveryReceiptErrorCode.from(789))) - .setStatus(Arrays.asList(DeliveryStatus.from("foo status1"), DeliveryStatus.CANCELLED)) - .setType(QueryReportType.from("foo type")) - .build(); - - when(api.get(eq("foo binary batch id"), eq(queryParameters))) - .thenReturn(deliveryReportBatchSMSDto); - - BatchDeliveryReport response = service.get("foo binary batch id", queryParameters); - - TestHelpers.recursiveEquals(response, deliveryReportBatchSMSDto); - } - - @Test - void getBatchDeliveryReportMMS() throws ApiException { - - BatchDeliveryReportQueryParameters queryParameters = - BatchDeliveryReportQueryParameters.builder() - .setCode( - Arrays.asList( - DeliveryReceiptErrorCode.from(456), DeliveryReceiptErrorCode.from(789))) - .setStatus(Arrays.asList(DeliveryStatus.from("foo status1"), DeliveryStatus.CANCELLED)) - .setType(QueryReportType.from("foo type")) - .build(); - - when(api.get(eq("foo binary batch id"), eq(queryParameters))) - .thenReturn(deliveryReportBatchMMSDto); - - BatchDeliveryReport response = service.get("foo binary batch id", queryParameters); - - TestHelpers.recursiveEquals(response, deliveryReportBatchMMSDto); + TestHelpers.recursiveEquals(response, batchDeliveryReportSMSDto); } @Test - void getRecipientDeliveryReportSMS() throws ApiException { - - when(api.getForNumber(eq("foo binary batch id"), eq("foo number"))) - .thenReturn(deliveryReportRecipientSMSDto); + void getRecipientDeliveryReport() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/batches/foo%20binary%20batch%20id/delivery_report/foo%20number", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonRecipientDeliveryReportMMSDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); RecipientDeliveryReport response = service.getForNumber("foo binary batch id", "foo number"); - TestHelpers.recursiveEquals(response, deliveryReportRecipientSMSDto); + TestHelpers.recursiveEquals(response, recipientDeliveryReportMMSDto); } @Test - void getRecipientDeliveryReportMMS() throws ApiException { - - when(api.getForNumber(eq("foo binary batch id"), eq("foo number"))) - .thenReturn(deliveryReportRecipientMMSDto); - - RecipientDeliveryReport response = service.getForNumber("foo binary batch id", "foo number"); - - TestHelpers.recursiveEquals(response, deliveryReportRecipientMMSDto); + void listDefault() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/delivery_reports", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListDeliveryReportResponseDtoPage0.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + ListDeliveryReportsResponse response = service.list(); + TestHelpers.recursiveEquals( + response.getContent(), listDeliveryReportResponseDtoPage0.getItems()); } @Test void list() throws ApiException { - ListDeliveryReportsQueryParameters page1 = - ListDeliveryReportsQueryParameters.builder().setPage(1).build(); - ListDeliveryReportsQueryParameters page2 = - ListDeliveryReportsQueryParameters.builder().setPage(2).build(); - - when(api.list(eq(null))).thenReturn(listDeliveryReportResponseDtoPage0); - when(api.list(eq(page1))).thenReturn(listDeliveryReportResponseDtoPage1); - when(api.list(eq(page2))).thenReturn(listDeliveryReportResponseDtoPage2); + List commonParameters = + Arrays.asList( + "page_size", + 2, + STYLE.FORM, + true, + "start_date", + "2023-11-03T15:21:21.113Z", + STYLE.FORM, + true, + "end_date", + "2023-12-12T15:54:21.321Z", + STYLE.FORM, + true, + "status", + Arrays.asList(DeliveryStatus.QUEUED, DeliveryStatus.DISPATCHED), + STYLE.FORM, + false, + "code", + Arrays.asList( + DeliveryReceiptErrorCode.DISPATCHED, DeliveryReceiptErrorCode.UNPROVISIONED_REGION), + STYLE.FORM, + false, + "client_reference", + "client reference", + STYLE.FORM, + true); + + Collection urlParameters0 = + PaginationFillerHelper.parametersFiller("page", 0, STYLE.FORM, true, commonParameters); + Collection urlParameters1 = + PaginationFillerHelper.parametersFiller("page", 1, STYLE.FORM, true, commonParameters); + Collection urlParameters2 = + PaginationFillerHelper.parametersFiller("page", 2, STYLE.FORM, true, commonParameters); + + HttpRequest httpRequest0 = + new HttpRequest( + "/xms/v1/foovalue/delivery_reports", + HttpMethod.GET, + urlParameters0, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpRequest httpRequest1 = + new HttpRequest( + "/xms/v1/foovalue/delivery_reports", + HttpMethod.GET, + urlParameters1, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpRequest httpRequest2 = + new HttpRequest( + "/xms/v1/foovalue/delivery_reports", + HttpMethod.GET, + urlParameters2, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse0 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListDeliveryReportResponseDtoPage0.getBytes()); + HttpResponse httpResponse1 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListDeliveryReportResponseDtoPage1.getBytes()); + HttpResponse httpResponse2 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListDeliveryReportResponseDtoPage2.getBytes()); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest0)))) + .thenReturn(httpResponse0); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest1)))) + .thenReturn(httpResponse1); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest2)))) + .thenReturn(httpResponse2); + + ListDeliveryReportsQueryParameters initialRequest = + ListDeliveryReportsQueryParameters.builder() + .setPage(0) + .setPageSize(2) + .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) + .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) + .setStatus(Arrays.asList(DeliveryStatus.QUEUED, DeliveryStatus.DISPATCHED)) + .setCode( + Arrays.asList( + DeliveryReceiptErrorCode.DISPATCHED, + DeliveryReceiptErrorCode.UNPROVISIONED_REGION)) + .setClientReference("client reference") + .build(); - ListDeliveryReportsResponse response = service.list(null); + ListDeliveryReportsResponse response = service.list(initialRequest); Iterator iterator = response.iterator(); + RecipientDeliveryReport item = iterator.next(); + TestHelpers.recursiveEquals(item, listDeliveryReportResponseDtoPage0.getItems().get(0)); Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - TestHelpers.recursiveEquals( - item, - RecipientDeliveryReportSMS.builder() - .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") - .setRecipient("+44231235674") - .setCode(DeliveryReceiptErrorCode.DISPATCHED) - .setStatus(DeliveryStatus.DISPATCHED) - .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) - .setOperator("operator") - .setAppliedOriginator("applied originator") - .setClientReference("client reference") - .setEncoding(EncodingType.from("encoding")) - .setNumberOfMessageParts(123) - .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) - .build()); - item = iterator.next(); + TestHelpers.recursiveEquals(item, listDeliveryReportResponseDtoPage0.getItems().get(1)); Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - TestHelpers.recursiveEquals( - item, - RecipientDeliveryReportMMS.builder() - .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") - .setRecipient("+44231235674") - .setCode(DeliveryReceiptErrorCode.DISPATCHED) - .setStatus(DeliveryStatus.DISPATCHED) - .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) - .setOperator("operator") - .setAppliedOriginator("applied originator") - .setClientReference("client reference") - .setEncoding(EncodingType.from("encoding")) - .setNumberOfMessageParts(123) - .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) - .build()); item = iterator.next(); + TestHelpers.recursiveEquals(item, listDeliveryReportResponseDtoPage1.getItems().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); - TestHelpers.recursiveEquals( - item, - RecipientDeliveryReportSMS.builder() - .setBatchId("01FC66621XXXXX119Z8PMV1QPQ") - .setRecipient("+44231235674") - .setCode(DeliveryReceiptErrorCode.from(401)) - .setStatus(DeliveryStatus.DISPATCHED) - .setCreatedAt(Instant.parse("2022-08-30T08:16:08.930Z")) - .setOperator("operator") - .setAppliedOriginator("applied originator") - .setClientReference("client reference") - .setEncoding(EncodingType.from("encoding")) - .setNumberOfMessageParts(123) - .setOperatorStatusAt(Instant.parse("2022-08-30T08:16:08.150Z")) - .build()); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java index a49f244d8..47087cf58 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java @@ -1,217 +1,364 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.sms.api.v1.internal.GroupsApi; -import com.sinch.sdk.domains.sms.models.v1.groups.AddKeyword; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.PaginationFillerHelper; +import com.sinch.sdk.domains.sms.api.v1.GroupsService; import com.sinch.sdk.domains.sms.models.v1.groups.Group; -import com.sinch.sdk.domains.sms.models.v1.groups.GroupAutoUpdate; -import com.sinch.sdk.domains.sms.models.v1.groups.RemoveKeyword; import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; -import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequestDtoTest; import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; import com.sinch.sdk.domains.sms.models.v1.groups.response.internal.ApiGroupList; -import com.sinch.sdk.models.SmsContext; -import java.time.Instant; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashSet; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.Mock; @TestWithResources class GroupsServiceTest extends BaseTest { - @Mock SmsContext context; - @Mock HttpClient httpClient; - @Mock Map authManagers; - @Mock GroupsApi api; - GroupsService service; - String uriPartID = "foovalue"; + static final String SMS_AUTH_NAMES = "BearerAuth"; - @Captor ArgumentCaptor groupIdCaptor; + @GivenTextResource("/domains/sms/v1/groups/GroupDto.json") + String jsonGroupDto; @GivenJsonResource("/domains/sms/v1/groups/GroupDto.json") - Group groupResponseDto; + Group groupDto; + + @GivenTextResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json") + String jsonListGroupsResponseDtoPage0; @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage0.json") - ApiGroupList groupsListResponseDtoPage0; + ApiGroupList listGroupsResponseDtoPage0; + + @GivenTextResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json") + String jsonListGroupsResponseDtoPage1; @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage1.json") - ApiGroupList groupsListResponseDtoPage1; + ApiGroupList listGroupsResponseDtoPage1; + + @GivenTextResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage2.json") + String jsonListGroupsResponseDtoPage2; - @GivenJsonResource("/domains/sms/v1/groups/response/ListGroupsResponseDtoPage2.json") - ApiGroupList groupsListResponseDtoPage2; + @Mock ServerConfiguration serverConfiguration; + @Mock HttpClient httpClient; + @Mock Map authManagers; + GroupsService service; @BeforeEach public void initMocks() { - service = spy(new GroupsService(uriPartID, context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); + service = + new GroupsServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); } @Test void get() throws ApiException { - when(api.retrieveGroup(eq("foo group ID"))).thenReturn(groupResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups/foo%20group%20ID", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonGroupDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); Group response = service.get("foo group ID"); - TestHelpers.recursiveEquals(response, groupResponseDto); + TestHelpers.recursiveEquals(response, groupDto); } @Test void create() throws ApiException { - when(api.createGroup(eq(GroupRequest.builder().setName("foo").build()))) - .thenReturn(groupResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups", + HttpMethod.POST, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), + GroupRequest.builder().setName("foo").build()), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonGroupDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); Group response = service.create(GroupRequest.builder().setName("foo").build()); - TestHelpers.recursiveEquals(response, groupResponseDto); + TestHelpers.recursiveEquals(response, groupDto); } @Test - void list() throws ApiException { - - ListGroupsQueryParameters page1 = ListGroupsQueryParameters.builder().setPage(1).build(); - ListGroupsQueryParameters page2 = ListGroupsQueryParameters.builder().setPage(2).build(); + void listDefault() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListGroupsResponseDtoPage0.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + ListGroupsResponse response = service.list(); + TestHelpers.recursiveEquals(response.getContent(), listGroupsResponseDtoPage0.getItems()); + } - when(api.listGroups(eq(null))).thenReturn(groupsListResponseDtoPage0); - when(api.listGroups(page1)).thenReturn(groupsListResponseDtoPage1); - when(api.listGroups(page2)).thenReturn(groupsListResponseDtoPage2); + @Test + void list() throws ApiException { - ListGroupsResponse response = service.list(null); + List commonParameters = Arrays.asList("page_size", 2, STYLE.FORM, true); + + Collection urlParameters0 = + PaginationFillerHelper.parametersFiller("page", 0, STYLE.FORM, true, commonParameters); + Collection urlParameters1 = + PaginationFillerHelper.parametersFiller("page", 1, STYLE.FORM, true, commonParameters); + Collection urlParameters2 = + PaginationFillerHelper.parametersFiller("page", 2, STYLE.FORM, true, commonParameters); + + HttpRequest httpRequest0 = + new HttpRequest( + "/xms/v1/foovalue/groups", + HttpMethod.GET, + urlParameters0, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpRequest httpRequest1 = + new HttpRequest( + "/xms/v1/foovalue/groups", + HttpMethod.GET, + urlParameters1, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpRequest httpRequest2 = + new HttpRequest( + "/xms/v1/foovalue/groups", + HttpMethod.GET, + urlParameters2, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse0 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListGroupsResponseDtoPage0.getBytes()); + HttpResponse httpResponse1 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListGroupsResponseDtoPage1.getBytes()); + HttpResponse httpResponse2 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonListGroupsResponseDtoPage2.getBytes()); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest0)))) + .thenReturn(httpResponse0); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest1)))) + .thenReturn(httpResponse1); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest2)))) + .thenReturn(httpResponse2); + + ListGroupsQueryParameters initialRequest = + ListGroupsQueryParameters.builder().setPage(0).setPageSize(2).build(); + + ListGroupsResponse response = service.list(initialRequest); Iterator iterator = response.iterator(); + Group item = iterator.next(); + TestHelpers.recursiveEquals(item, listGroupsResponseDtoPage0.getItems().get(0)); Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - TestHelpers.recursiveEquals( - item, - Group.builder() - .setId("01FC66621XXXXX119Z8PMV1QPU") - .setName("My new customers") - .setSize(2) - .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) - .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) - .setAutoUpdate( - GroupAutoUpdate.builder() - .setTo("15551231234") - .setAdd(AddKeyword.builder().setFirstWord("1stKeyword").build()) - .setRemove( - RemoveKeyword.builder() - .setFirstWord("1stKeyword") - .setSecondWord("2ndKeyword") - .build()) - .build()) - .setChildGroups( - new HashSet<>( - Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) - .build()); - item = iterator.next(); + TestHelpers.recursiveEquals(item, listGroupsResponseDtoPage0.getItems().get(1)); Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - TestHelpers.recursiveEquals(item, Group.builder().setId("foo id").build()); item = iterator.next(); + TestHelpers.recursiveEquals(item, listGroupsResponseDtoPage1.getItems().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); - TestHelpers.recursiveEquals( - item, - Group.builder() - .setId("01FC66621XXXXX119Z8PMV1QPU") - .setName("My new customers") - .setSize(2) - .setCreatedAt(Instant.parse("2019-08-24T14:15:22Z")) - .setModifiedAt(Instant.parse("2019-08-24T14:15:44Z")) - .setAutoUpdate( - GroupAutoUpdate.builder() - .setTo("15551231234") - .setAdd(AddKeyword.builder().setFirstWord("1stKeyword").build()) - .setRemove( - RemoveKeyword.builder() - .setFirstWord("1stKeyword") - .setSecondWord("2ndKeyword") - .build()) - .build()) - .setChildGroups( - new HashSet<>( - Arrays.asList("01FC66621XXXXX119Z8PMV1AHY", "01FC66621XXXXX119Z8PMV1A00"))) - .build()); } @Test void replace() throws ApiException { - when(api.replaceGroup( - eq("group id"), - eq( - GroupRequest.builder() - .setName("foo name") - .setMembers(Collections.singleton("foo member")) - .build()))) - .thenReturn(groupResponseDto); - - Group response = - service.replace( - "group id", - GroupRequest.builder() - .setName("foo name") - .setMembers(Collections.singleton("foo member")) - .build()); - - TestHelpers.recursiveEquals(response, groupResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups/group%20id", + HttpMethod.PUT, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), + GroupRequest.builder().setName("foo").build()), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonGroupDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + Group response = service.replace("group id", GroupRequest.builder().setName("foo").build()); + + TestHelpers.recursiveEquals(response, groupDto); } @Test void update() throws ApiException { - when(api.updateGroup( - eq("group id"), eq(GroupUpdateRequest.builder().setName("foo name").build()))) - .thenReturn(groupResponseDto); - - Group response = - service.update("group id", GroupUpdateRequest.builder().setName("foo name").build()); - - TestHelpers.recursiveEquals(response, groupResponseDto); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups/group%20id", + HttpMethod.POST, + Collections.emptyList(), + HttpMapper.getInstance() + .serialize( + Collections.singletonList(HttpContentType.APPLICATION_JSON), + GroupUpdateRequestDtoTest.requestDTO), + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonGroupDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + Group response = service.update("group id", GroupUpdateRequestDtoTest.requestDTO); + + TestHelpers.recursiveEquals(response, groupDto); } @Test void delete() throws ApiException { - service.delete("foo group id"); - - verify(api).deleteGroup(groupIdCaptor.capture()); - - String parameter = groupIdCaptor.getValue(); - Assertions.assertThat(parameter).isEqualTo("foo group id"); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups/group%20id", + HttpMethod.DELETE, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.emptyList(), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + service.delete("group id"); } @Test void listMembers() throws ApiException { - when(api.getMembers(eq("group id"))).thenReturn(Arrays.asList("entry 1", "entry 2")); - - Collection response = service.listMembers("group id"); - - TestHelpers.recursiveEquals(response, Arrays.asList("entry 1", "entry 2")); + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/groups/group%20id/members", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), "[\"entry 1\", \"entry 2\"]".getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + Collection members = service.listMembers("group id"); + TestHelpers.recursiveEquals(members, new ArrayList<>(Arrays.asList("entry 1", "entry 2"))); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java index 5f0d585a2..1a9d661f7 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java @@ -1,27 +1,39 @@ package com.sinch.sdk.domains.sms.api.v1.adapters; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.when; import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; import com.adelean.inject.resources.junit.jupiter.TestWithResources; import com.sinch.sdk.BaseTest; import com.sinch.sdk.core.TestHelpers; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.http.AuthManager; import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.domains.sms.api.v1.internal.InboundsApi; -import com.sinch.sdk.domains.sms.models.v1.inbounds.BinaryMessage; +import com.sinch.sdk.core.http.HttpContentType; +import com.sinch.sdk.core.http.HttpMapper; +import com.sinch.sdk.core.http.HttpMethod; +import com.sinch.sdk.core.http.HttpRequest; +import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; +import com.sinch.sdk.core.http.HttpResponse; +import com.sinch.sdk.core.http.URLParameter; +import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.PaginationFillerHelper; +import com.sinch.sdk.domains.sms.api.v1.InboundsService; import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; -import com.sinch.sdk.models.SmsContext; import java.time.Instant; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.Iterator; +import java.util.List; import java.util.Map; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; @@ -29,134 +41,211 @@ import org.mockito.Mock; @TestWithResources -class InboundsServiceTest extends BaseTest { +public class InboundsServiceTest extends BaseTest { - @Mock SmsContext context; - @Mock HttpClient httpClient; - @Mock Map authManagers; - @Mock InboundsApi api; - InboundsService service; - - String uriPartID = "foovalue"; + static final String SMS_AUTH_NAMES = "BearerAuth"; - @GivenJsonResource("/domains/sms/v1/inbounds/InboundBinaryDto.json") - InboundMessage binary; + @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") + String jsonTextMessageDto; @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") - InboundMessage text; + TextMessage textMessageDto; - @GivenJsonResource("/domains/sms/v1/inbounds/InboundMediaDto.json") - InboundMessage media; + @GivenTextResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") + String jsonInboundsListResponseDto0; @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") - ApiInboundList inboundsLisResponseDtoPage0; + ApiInboundList listInboundsListResponseDto0; - @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json") - ApiInboundList inboundsLisResponseDtoPage1; - - @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json") - ApiInboundList inboundsLisResponseDtoPage2; + @GivenTextResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json") + String jsonInboundsListResponseDto1; - @BeforeEach - public void initMocks() { - service = spy(new InboundsService(uriPartID, context, httpClient, authManagers)); - doReturn(api).when(service).getApi(); - } + @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage1.json") + ApiInboundList listInboundsListResponseDto1; - @Test - void getBinary() throws ApiException { + @GivenTextResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage2.json") + String jsonInboundsListResponseDto2; - when(api.get(eq("foo inbound ID"))).thenReturn(binary); + @Mock HttpClient httpClient; + @Mock ServerConfiguration serverConfiguration; + @Mock Map authManagers; - InboundMessage response = service.get("foo inbound ID"); + InboundsService service; - TestHelpers.recursiveEquals(response, binary); + @BeforeEach + public void initMocks() { + service = + new InboundsServiceImpl( + httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); } @Test - void getText() throws ApiException { - - when(api.get(eq("foo inbound ID"))).thenReturn(text); - - InboundMessage response = service.get("foo inbound ID"); - - TestHelpers.recursiveEquals(response, text); + void get() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/inbounds/foo%20binary%20batch%20id", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse(200, null, Collections.emptyMap(), jsonTextMessageDto.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + InboundMessage response = service.get("foo binary batch id"); + + TestHelpers.recursiveEquals(response, textMessageDto); } @Test - void getMedia() throws ApiException { - - when(api.get(eq("foo inbound ID"))).thenReturn(media); - - InboundMessage response = service.get("foo inbound ID"); - - TestHelpers.recursiveEquals(response, media); + void listDefault() throws ApiException { + + HttpRequest httpRequest = + new HttpRequest( + "/xms/v1/foovalue/inbounds", + HttpMethod.GET, + Collections.emptyList(), + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonInboundsListResponseDto0.getBytes()); + + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest)))) + .thenReturn(httpResponse); + + ListInboundsResponse response = service.list(); + TestHelpers.recursiveEquals(response.getContent(), listInboundsListResponseDto0.getItems()); } @Test void list() throws ApiException { - ListInboundMessagesQueryParameters initialRequest = - ListInboundMessagesQueryParameters.builder().build(); - ListInboundMessagesQueryParameters page1 = - ListInboundMessagesQueryParameters.builder().setPage(1).build(); - ListInboundMessagesQueryParameters page2 = - ListInboundMessagesQueryParameters.builder().setPage(2).build(); + List commonParameters = + Arrays.asList( + "page_size", + 2, + STYLE.FORM, + true, + "to", + "+1234567890", + STYLE.FORM, + true, + "start_date", + "2023-11-03T15:21:21.113Z", + STYLE.FORM, + true, + "end_date", + "2023-12-12T15:54:21.321Z", + STYLE.FORM, + true, + "client_reference", + "client reference", + STYLE.FORM, + true); + + Collection urlParameters0 = + PaginationFillerHelper.parametersFiller("page", 0, STYLE.FORM, true, commonParameters); + Collection urlParameters1 = + PaginationFillerHelper.parametersFiller("page", 1, STYLE.FORM, true, commonParameters); + Collection urlParameters2 = + PaginationFillerHelper.parametersFiller("page", 2, STYLE.FORM, true, commonParameters); + + HttpRequest httpRequest0 = + new HttpRequest( + "/xms/v1/foovalue/inbounds", + HttpMethod.GET, + urlParameters0, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpRequest httpRequest1 = + new HttpRequest( + "/xms/v1/foovalue/inbounds", + HttpMethod.GET, + urlParameters1, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpRequest httpRequest2 = + new HttpRequest( + "/xms/v1/foovalue/inbounds", + HttpMethod.GET, + urlParameters2, + null, + Collections.emptyMap(), + Collections.singletonList(HttpContentType.APPLICATION_JSON), + Collections.emptyList(), + Collections.singletonList(SMS_AUTH_NAMES)); + HttpResponse httpResponse0 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonInboundsListResponseDto0.getBytes()); + HttpResponse httpResponse1 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonInboundsListResponseDto1.getBytes()); + HttpResponse httpResponse2 = + new HttpResponse( + 200, null, Collections.emptyMap(), jsonInboundsListResponseDto2.getBytes()); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest0)))) + .thenReturn(httpResponse0); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest1)))) + .thenReturn(httpResponse1); + when(httpClient.invokeAPI( + eq(serverConfiguration), + eq(authManagers), + argThat(new HttpRequestMatcher(httpRequest2)))) + .thenReturn(httpResponse2); - when(api.list(initialRequest)).thenReturn(inboundsLisResponseDtoPage0); - when(api.list(page1)).thenReturn(inboundsLisResponseDtoPage1); - when(api.list(page2)).thenReturn(inboundsLisResponseDtoPage2); + ListInboundMessagesQueryParameters initialRequest = + ListInboundMessagesQueryParameters.builder() + .setPage(0) + .setPageSize(2) + .setTo(Arrays.asList("+1234567890")) + .setClientReference("client reference") + .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) + .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) + .build(); ListInboundsResponse response = service.list(initialRequest); Iterator iterator = response.iterator(); + InboundMessage item = iterator.next(); - Assertions.assertThat(item) - .usingRecursiveComparison() - .isEqualTo( - BinaryMessage.builder() - .setBody("a body") - .setClientReference("a client reference") - .setFrom("+11203494390") - .setId("01FC66621XXXXX119Z8PMV1QPA") - .setOperatorId("35000") - .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) - .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) - .setTo("11203453453") - .setUdh("foo udh") - .build()); + TestHelpers.recursiveEquals(item, listInboundsListResponseDto0.getItems().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); item = iterator.next(); + TestHelpers.recursiveEquals(item, listInboundsListResponseDto0.getItems().get(1)); Assertions.assertThat(iterator.hasNext()).isEqualTo(true); - Assertions.assertThat(item) - .usingRecursiveComparison() - .isEqualTo( - TextMessage.builder() - .setBody("a body") - .setClientReference("a client reference") - .setFrom("+11203494390") - .setId("01FC66621XXXXX119Z8PMV1QPA") - .setOperatorId("35000") - .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) - .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) - .setTo("11203453453") - .build()); item = iterator.next(); + TestHelpers.recursiveEquals(item, listInboundsListResponseDto1.getItems().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); - Assertions.assertThat(item) - .usingRecursiveComparison() - .isEqualTo( - BinaryMessage.builder() - .setBody("a body") - .setClientReference("a client reference") - .setFrom("+11203494390") - .setId("01FC66621XXXXX119Z8PMV1QPA") - .setOperatorId("35000") - .setReceivedAt(Instant.parse("2019-08-24T14:17:22Z")) - .setSentAt(Instant.parse("2019-08-24T14:15:22Z")) - .setTo("11203453453") - .setUdh("foo udh") - .build()); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java deleted file mode 100644 index c486d30c8..000000000 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApiTest.java +++ /dev/null @@ -1,332 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1.internal; - -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; -import com.adelean.inject.resources.junit.jupiter.GivenTextResource; -import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.sinch.sdk.BaseTest; -import com.sinch.sdk.core.TestHelpers; -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.AuthManager; -import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.core.http.HttpContentType; -import com.sinch.sdk.core.http.HttpMapper; -import com.sinch.sdk.core.http.HttpMethod; -import com.sinch.sdk.core.http.HttpRequest; -import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; -import com.sinch.sdk.core.http.HttpResponse; -import com.sinch.sdk.core.http.URLParameter; -import com.sinch.sdk.core.http.URLParameter.STYLE; -import com.sinch.sdk.core.models.ServerConfiguration; -import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.TextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateTextRequest; -import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; -import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -@TestWithResources -public class BatchesApiTest extends BaseTest { - - static final String SMS_AUTH_NAMES = "BearerAuth"; - - @GivenJsonResource("/domains/sms/v1/batches/request/TextRequestDto.json") - TextRequest textRequestDto; - - @GivenTextResource("/domains/sms/v1/batches/response/TextResponseDto.json") - String jsonTextResponseDto; - - @GivenJsonResource("/domains/sms/v1/batches/response/TextResponseDto.json") - BatchResponse textResponseDto; - - @GivenTextResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") - String jsonDryRunResponseDto; - - @GivenJsonResource("/domains/sms/v1/batches/response/DryRunResponseDto.json") - DryRunResponse dryRunResponseDto; - - @GivenTextResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") - String jsonBatchesResponseDtoPage0; - - @GivenJsonResource("/domains/sms/v1/batches/response/ListBatchesResponseDtoPage0.json") - ApiBatchList listBatchesResponseDtoPage0; - - @GivenJsonResource("/domains/sms/v1/batches/request/UpdateTextRequestDto.json") - UpdateTextRequest updateTextRequestDto; - - @GivenJsonResource("/domains/sms/v1/batches/request/SendDeliveryFeedbackRequestDto.json") - SendDeliveryFeedbackRequest sendDeliveryFeedbackRequestDto; - - @Mock HttpClient httpClient; - @Mock ServerConfiguration serverConfiguration; - - HttpMapper httpMapper = new HttpMapper(); - @Mock Map authManagers; - BatchesApi api; - String uriPartID = "foovalue"; - - @BeforeEach - public void initMocks() { - api = spy(new BatchesApi(httpClient, serverConfiguration, authManagers, httpMapper, uriPartID)); - } - - @Test - void get() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches/foo%20binary%20batch%20id", - HttpMethod.GET, - Collections.emptyList(), - null, - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.emptyList(), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - BatchResponse response = api.get("foo binary batch id"); - - TestHelpers.recursiveEquals(response, textResponseDto); - } - - @Test - void send() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches", - HttpMethod.POST, - Collections.emptyList(), - httpMapper.serialize( - Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - BatchResponse response = api.send(textRequestDto); - - TestHelpers.recursiveEquals(response, textResponseDto); - } - - @Test - void dryRun() throws ApiException { - - DryRunQueryParameters queryParameters = - DryRunQueryParameters.builder().setPerRecipient(true).setNumberOfRecipients(456).build(); - - Collection urlParameters = - Arrays.asList( - new URLParameter("per_recipient", true, STYLE.FORM, true), - new URLParameter("number_of_recipients", 456, STYLE.FORM, true)); - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches/dry_run", - HttpMethod.POST, - urlParameters, - httpMapper.serialize( - Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonDryRunResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - DryRunResponse response = api.dryRun(queryParameters, textRequestDto); - - TestHelpers.recursiveEquals(response, dryRunResponseDto); - } - - @Test - void list() throws ApiException { - - Collection urlParameters = - Arrays.asList( - new URLParameter("page", 1, STYLE.FORM, true), - new URLParameter("page_size", 2, STYLE.FORM, true), - new URLParameter("from", "+1234567890", STYLE.FORM, true), - new URLParameter("start_date", "2023-11-03T15:21:21.113Z", STYLE.FORM, true), - new URLParameter("end_date", "2023-12-12T15:54:21.321Z", STYLE.FORM, true), - new URLParameter("client_reference", "client reference", STYLE.FORM, true)); - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches", - HttpMethod.GET, - urlParameters, - null, - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.emptyList(), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonBatchesResponseDtoPage0.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - ListBatchesQueryParameters initialRequest = - ListBatchesQueryParameters.builder() - .setPage(1) - .setPageSize(2) - .setFrom("+1234567890") - .setClientReference("client reference") - .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) - .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) - .build(); - - ApiBatchList response = api.list(initialRequest); - - TestHelpers.recursiveEquals(response, listBatchesResponseDtoPage0); - } - - @Test - void update() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id", - HttpMethod.POST, - Collections.emptyList(), - httpMapper.serialize( - Collections.singletonList(HttpContentType.APPLICATION_JSON), updateTextRequestDto), - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - BatchResponse response = api.update("foo text batch id", updateTextRequestDto); - - TestHelpers.recursiveEquals(response, textResponseDto); - } - - @Test - void replace() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id", - HttpMethod.PUT, - Collections.emptyList(), - httpMapper.serialize( - Collections.singletonList(HttpContentType.APPLICATION_JSON), textRequestDto), - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - BatchResponse response = api.replace("foo text batch id", textRequestDto); - - TestHelpers.recursiveEquals(response, textResponseDto); - } - - @Test - void cancel() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id", - HttpMethod.DELETE, - Collections.emptyList(), - null, - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.emptyList(), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonTextResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - BatchResponse response = api.cancel("foo text batch id"); - - TestHelpers.recursiveEquals(response, textResponseDto); - } - - @Test - void sendDeliveryFeedback() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id/delivery_feedback", - HttpMethod.POST, - Collections.emptyList(), - httpMapper.serialize( - Collections.singletonList(HttpContentType.APPLICATION_JSON), - sendDeliveryFeedbackRequestDto), - Collections.emptyMap(), - Collections.emptyList(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = new HttpResponse(200, null, Collections.emptyMap(), null); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - api.sendDeliveryFeedback("foo text batch id", sendDeliveryFeedbackRequestDto); - } -} diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java deleted file mode 100644 index bb31e10ed..000000000 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApiTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package com.sinch.sdk.domains.sms.api.v1.internal; - -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -import com.adelean.inject.resources.junit.jupiter.GivenJsonResource; -import com.adelean.inject.resources.junit.jupiter.GivenTextResource; -import com.adelean.inject.resources.junit.jupiter.TestWithResources; -import com.sinch.sdk.BaseTest; -import com.sinch.sdk.core.TestHelpers; -import com.sinch.sdk.core.exceptions.ApiException; -import com.sinch.sdk.core.http.AuthManager; -import com.sinch.sdk.core.http.HttpClient; -import com.sinch.sdk.core.http.HttpContentType; -import com.sinch.sdk.core.http.HttpMapper; -import com.sinch.sdk.core.http.HttpMethod; -import com.sinch.sdk.core.http.HttpRequest; -import com.sinch.sdk.core.http.HttpRequestTest.HttpRequestMatcher; -import com.sinch.sdk.core.http.HttpResponse; -import com.sinch.sdk.core.http.URLParameter; -import com.sinch.sdk.core.http.URLParameter.STYLE; -import com.sinch.sdk.core.models.ServerConfiguration; -import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; -import com.sinch.sdk.domains.sms.models.v1.inbounds.TextMessage; -import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; -import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; -import java.time.Instant; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mock; - -@TestWithResources -public class InboundsApiTest extends BaseTest { - - static final String SMS_AUTH_NAMES = "BearerAuth"; - - @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") - String jsonTextMessageDto; - - @GivenJsonResource("/domains/sms/v1/inbounds/InboundTextDto.json") - TextMessage textMessageDto; - - @GivenTextResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") - String jsonInboundsListResponseDto; - - @GivenJsonResource("/domains/sms/v1/inbounds/response/internal/InboundsListResponseDtoPage0.json") - ApiInboundList listInboundsListResponseDto; - - @Mock HttpClient httpClient; - @Mock ServerConfiguration serverConfiguration; - - HttpMapper httpMapper = new HttpMapper(); - @Mock Map authManagers; - InboundsApi api; - String uriPartID = "foovalue"; - - @BeforeEach - public void initMocks() { - api = - spy(new InboundsApi(httpClient, serverConfiguration, authManagers, httpMapper, uriPartID)); - } - - @Test - void get() throws ApiException { - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/inbounds/foo%20binary%20batch%20id", - HttpMethod.GET, - Collections.emptyList(), - null, - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.emptyList(), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonTextMessageDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - InboundMessage response = api.get("foo binary batch id"); - - TestHelpers.recursiveEquals(response, textMessageDto); - } - - @Test - void list() throws ApiException { - - Collection urlParameters = - Arrays.asList( - new URLParameter("page", 1, STYLE.FORM, true), - new URLParameter("page_size", 2, STYLE.FORM, true), - new URLParameter("to", "+1234567890", STYLE.FORM, true), - new URLParameter("start_date", "2023-11-03T15:21:21.113Z", STYLE.FORM, true), - new URLParameter("end_date", "2023-12-12T15:54:21.321Z", STYLE.FORM, true), - new URLParameter("client_reference", "client reference", STYLE.FORM, true)); - - HttpRequest httpRequest = - new HttpRequest( - "/xms/v1/foovalue/inbounds", - HttpMethod.GET, - urlParameters, - null, - Collections.emptyMap(), - Collections.singletonList(HttpContentType.APPLICATION_JSON), - Collections.emptyList(), - Collections.singletonList(SMS_AUTH_NAMES)); - HttpResponse httpResponse = - new HttpResponse(200, null, Collections.emptyMap(), jsonInboundsListResponseDto.getBytes()); - - when(httpClient.invokeAPI( - eq(serverConfiguration), - eq(authManagers), - argThat(new HttpRequestMatcher(httpRequest)))) - .thenReturn(httpResponse); - - ListInboundMessagesQueryParameters initialRequest = - ListInboundMessagesQueryParameters.builder() - .setPage(1) - .setPageSize(2) - .setTo(Arrays.asList("+1234567890")) - .setClientReference("client reference") - .setStartDate(Instant.parse("2023-11-03T15:21:21.113Z")) - .setEndDate(Instant.parse("2023-12-12T15:54:21.321Z")) - .build(); - - ApiInboundList response = api.list(initialRequest); - - TestHelpers.recursiveEquals(response, listInboundsListResponseDto); - } -} diff --git a/core/src/main/com/sinch/sdk/core/http/HttpMapper.java b/core/src/main/com/sinch/sdk/core/http/HttpMapper.java index 4fa8da25e..da081ba10 100644 --- a/core/src/main/com/sinch/sdk/core/http/HttpMapper.java +++ b/core/src/main/com/sinch/sdk/core/http/HttpMapper.java @@ -62,4 +62,13 @@ public String serialize(Collection contentTypes, Object body) { throw new ApiException( "Deserialization for content type '" + contentTypes + "' not supported "); } + + public static HttpMapper getInstance() { + return LazyHolder.INSTANCE; + } + + private static class LazyHolder { + + public static final HttpMapper INSTANCE = new HttpMapper(); + } } diff --git a/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java b/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java index 212c4c765..0fe1202ff 100644 --- a/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java +++ b/core/src/test/java/com/sinch/sdk/core/http/HttpRequestTest.java @@ -15,7 +15,11 @@ public HttpRequestMatcher(HttpRequest left) { @Override public boolean matches(HttpRequest right) { - TestHelpers.recursiveEquals(right, left); + try { + TestHelpers.recursiveEquals(right, left); + } catch (AssertionError e) { + return false; + } return true; } } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java index 73a215cef..e07b5c891 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/sms/models/v1/groups/request/GroupUpdateRequestDtoTest.java @@ -11,23 +11,23 @@ import org.skyscreamer.jsonassert.JSONAssert; @TestWithResources -class GroupUpdateRequestDtoTest extends BaseTest { +public class GroupUpdateRequestDtoTest extends BaseTest { @GivenTextResource("/domains/sms/v1/groups/request/GroupUpdateRequestDto.json") String jsonGroupUpdateRequestDto; + public static GroupUpdateRequest requestDTO = + GroupUpdateRequest.builder() + .setName("My new customers") + .setAdd(Arrays.asList("+12345674890")) + .setRemove(Arrays.asList("+0987654321", "+3456789123")) + .setAddFromGroup("01FC66621XXXXX119Z8PMV1AHY") + .setRemoveFromGroup("01FC66621XXXXX119Z8PMV1A00") + .setAutoUpdate(GroupDtoTest.groupResponse.getAutoUpdate()) + .build(); + @Test void serialize() throws JsonProcessingException, JSONException { - GroupUpdateRequest requestDTO = - GroupUpdateRequest.builder() - .setName("My new customers") - .setAdd(Arrays.asList("+12345674890")) - .setRemove(Arrays.asList("+0987654321", "+3456789123")) - .setAddFromGroup("01FC66621XXXXX119Z8PMV1AHY") - .setRemoveFromGroup("01FC66621XXXXX119Z8PMV1A00") - .setAutoUpdate(GroupDtoTest.groupResponse.getAutoUpdate()) - .build(); - String serializedString = objectMapper.writeValueAsString(requestDTO); JSONAssert.assertEquals(jsonGroupUpdateRequestDto, serializedString, true); From 61be51b76bdc62c75708ec13fb0cde7d03298943 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Fri, 17 Jan 2025 11:18:29 +0100 Subject: [PATCH 55/65] feat (SMS): Generated service sources --- .../domains/sms/api/v1/BatchesService.java | 142 ++++++++++++ .../sms/api/v1/DeliveryReportsService.java | 78 +++++++ .../sdk/domains/sms/api/v1/GroupsService.java | 117 ++++++++++ .../domains/sms/api/v1/InboundsService.java | 50 ++++ .../BatchesServiceImpl.java} | 148 +++--------- .../DeliveryReportsServiceImpl.java} | 95 +++----- .../GroupsServiceImpl.java} | 219 ++++++------------ .../InboundsServiceImpl.java} | 63 ++--- .../response/internal/ApiBatchList.java | 10 +- .../response/internal/ApiBatchListImpl.java | 28 +-- .../response/internal/DeliveryReportList.java | 10 +- .../internal/DeliveryReportListImpl.java | 28 +-- .../response/internal/ApiGroupList.java | 12 +- .../response/internal/ApiGroupListImpl.java | 28 +-- .../response/internal/ApiInboundList.java | 10 +- .../response/internal/ApiInboundListImpl.java | 28 +-- 16 files changed, 617 insertions(+), 449 deletions(-) create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java create mode 100644 openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/{internal/BatchesApi.java => adapters/BatchesServiceImpl.java} (78%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/{internal/DeliveryReportsApi.java => adapters/DeliveryReportsServiceImpl.java} (79%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/{internal/GroupsApi.java => adapters/GroupsServiceImpl.java} (65%) rename openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/{internal/InboundsApi.java => adapters/InboundsServiceImpl.java} (81%) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java new file mode 100644 index 000000000..79feeba53 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -0,0 +1,142 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.batches.request.SendDeliveryFeedbackRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; +import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; + +public interface BatchesService { + + /** + * Cancel a batch message A batch can be canceled at any point. If a batch is canceled while + * it's currently being delivered some messages currently being processed might still be + * delivered. The delivery report will indicate which messages were canceled and which + * weren't. Canceling a batch scheduled in the future will result in an empty delivery report + * while canceling an already sent batch would result in no change to the completed delivery + * report. + * + * @param batchId The batch ID you received from sending a message. (required) + * @return BatchResponse + * @throws ApiException if fails to make API call + */ + BatchResponse cancel(String batchId) throws ApiException; + + /** + * Dry run (using default parameters) This operation will perform a dry run of a batch which + * calculates the bodies and number of parts for all messages in the batch without actually + * sending any messages. + * + * @param sendRequest (optional) + * @return DryRunResponse + * @throws ApiException if fails to make API call + */ + DryRunResponse dryRun(BatchRequest sendRequest) throws ApiException; + + /** + * Dry run This operation will perform a dry run of a batch which calculates the bodies and number + * of parts for all messages in the batch without actually sending any messages. + * + * @param queryParameter (optional) + * @param sendRequest (optional) + * @return DryRunResponse + * @throws ApiException if fails to make API call + */ + DryRunResponse dryRun(DryRunQueryParameters queryParameter, BatchRequest sendRequest) + throws ApiException; + + /** + * Get a batch message This operation returns a specific batch that matches the provided batch ID. + * + * @param batchId The batch ID you received from sending a message. (required) + * @return BatchResponse + * @throws ApiException if fails to make API call + */ + BatchResponse get(String batchId) throws ApiException; + + /** + * List Batches (using default parameters) With the list operation you can list batch messages + * created in the last 14 days that you have created. This operation supports pagination. + * + * @return ListBatchesResponse + * @throws ApiException if fails to make API call + */ + ListBatchesResponse list() throws ApiException; + + /** + * List Batches With the list operation you can list batch messages created in the last 14 days + * that you have created. This operation supports pagination. + * + * @param queryParameter (optional) + * @return ListBatchesResponse + * @throws ApiException if fails to make API call + */ + ListBatchesResponse list(ListBatchesQueryParameters queryParameter) throws ApiException; + + /** + * Replace a batch This operation will replace all the parameters of a batch with the provided + * values. It is the same as cancelling a batch and sending a new one instead. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param sendRequest (optional) + * @return BatchResponse + * @throws ApiException if fails to make API call + */ + BatchResponse replace(String batchId, BatchRequest sendRequest) throws ApiException; + + /** + * Send delivery feedback for a message Send feedback if your system can confirm successful + * message delivery. Feedback can only be provided if `feedback_enabled` was set when + * batch was submitted. **Batches**: It is possible to submit feedback multiple times for the same + * batch for different recipients. Feedback without specified recipients is treated as successful + * message delivery to all recipients referenced in the batch. Note that the + * `recipients` key is still required even if the value is empty. **Groups**: If the + * batch message was creating using a group ID, at least one recipient is required. Excluding + * recipients (an empty recipient list) does not work and will result in a failed request. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param sendDeliveryFeedbackRequest A list of phone numbers (MSISDNs) that successfully received + * the message. (required) + * @throws ApiException if fails to make API call + */ + void sendDeliveryFeedback(String batchId, SendDeliveryFeedbackRequest sendDeliveryFeedbackRequest) + throws ApiException; + + /** + * Send Send a message or a batch of messages. Depending on the length of the body, one message + * might be split into multiple parts and charged accordingly. Any groups targeted in a scheduled + * batch will be evaluated at the time of sending. If a group is deleted between batch creation + * and scheduled date, it will be considered empty. Be sure to use the correct + * [region](/docs/sms/api-reference/#base-url) in the server URL. + * + * @param sendRequest Default schema is Text if type is not specified. (optional) + * @return BatchResponse + * @throws ApiException if fails to make API call + */ + BatchResponse send(BatchRequest sendRequest) throws ApiException; + + /** + * Update a Batch message This operation updates all specified parameters of a batch that matches + * the provided batch ID. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param updateBatchRequest (optional) + * @return BatchResponse + * @throws ApiException if fails to make API call + */ + BatchResponse update(String batchId, UpdateBatchRequest updateBatchRequest) throws ApiException; +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java new file mode 100644 index 000000000..65e6bc91b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java @@ -0,0 +1,78 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; + +public interface DeliveryReportsService { + + /** + * Retrieve a delivery report (using default parameters) Delivery reports can be retrieved even if + * no callback was requested. The difference between a summary and a full report is only that the + * full report contains the phone numbers in + * [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format for each status code. + * + * @param batchId The batch ID you received from sending a message. (required) + * @return BatchDeliveryReport + * @throws ApiException if fails to make API call + */ + BatchDeliveryReport get(String batchId) throws ApiException; + + /** + * Retrieve a delivery report Delivery reports can be retrieved even if no callback was requested. + * The difference between a summary and a full report is only that the full report contains the + * phone numbers in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format for + * each status code. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param queryParameter (optional) + * @return BatchDeliveryReport + * @throws ApiException if fails to make API call + */ + BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters queryParameter) + throws ApiException; + + /** + * Retrieve a recipient delivery report A recipient delivery report contains the message status + * for a single recipient phone number. + * + * @param batchId The batch ID you received from sending a message. (required) + * @param recipientMsisdn Phone number for which you to want to search. (required) + * @return RecipientDeliveryReport + * @throws ApiException if fails to make API call + */ + RecipientDeliveryReport getForNumber(String batchId, String recipientMsisdn) throws ApiException; + + /** + * Retrieve a list of delivery reports (using default parameters) Get a list of finished delivery + * reports. This operation supports pagination. + * + * @return ListDeliveryReportsResponse + * @throws ApiException if fails to make API call + */ + ListDeliveryReportsResponse list() throws ApiException; + + /** + * Retrieve a list of delivery reports Get a list of finished delivery reports. This operation + * supports pagination. + * + * @param queryParameter (optional) + * @return ListDeliveryReportsResponse + * @throws ApiException if fails to make API call + */ + ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters queryParameter) + throws ApiException; +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java new file mode 100644 index 000000000..2aaf83813 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java @@ -0,0 +1,117 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.groups.Group; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; +import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; +import java.util.List; + +public interface GroupsService { + + /** + * Create a group This endpoint allows you to create a group of recipients. A new group must be + * created with a group name. This is represented by the `name` field which can be up to + * 20 charecters. In addition, there are a number of optional fields: - `members` field + * enables groups to be created with an initial list of contacts - `auto_update` allows + * customers to auto subscribe to a new group. This contains three fields. The `to` + * field contains the group creator's number. (This number **must be provisioned by contacting + * your account manager**.) The `add` and `remove` fields are objects + * containing the keywords that customers need to text to join or leave a group. + * + * @param groupRequest (optional) + * @return Group + * @throws ApiException if fails to make API call + */ + Group create(GroupRequest groupRequest) throws ApiException; + + /** + * Delete a group This operation deletes the group with the provided group ID. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @throws ApiException if fails to make API call + */ + void delete(String groupId) throws ApiException; + + /** + * Get phone numbers for a group This operation retrieves the members of the group with the + * provided group ID. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @return List<String> + * @throws ApiException if fails to make API call + */ + List listMembers(String groupId) throws ApiException; + + /** + * List Groups (using default parameters) With the list operation you can list all groups that you + * have created. This operation supports pagination. Groups are returned in reverse chronological + * order. + * + * @return ListGroupsResponse + * @throws ApiException if fails to make API call + */ + ListGroupsResponse list() throws ApiException; + + /** + * List Groups With the list operation you can list all groups that you have created. This + * operation supports pagination. Groups are returned in reverse chronological order. + * + * @param queryParameter (optional) + * @return ListGroupsResponse + * @throws ApiException if fails to make API call + */ + ListGroupsResponse list(ListGroupsQueryParameters queryParameter) throws ApiException; + + /** + * Replace a group The replace operation will replace all parameters, including members, of an + * existing group with new values. Replacing a group targeted by a batch message scheduled in the + * future is allowed and changes will be reflected when the batch is sent. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @param groupRequest (optional) + * @return Group + * @throws ApiException if fails to make API call + */ + Group replace(String groupId, GroupRequest groupRequest) throws ApiException; + + /** + * Retrieve a group This operation retrieves a specific group with the provided group ID. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @return Group + * @throws ApiException if fails to make API call + */ + Group get(String groupId) throws ApiException; + + /** + * Update a group With the update group operation, you can add and remove members in an existing + * group as well as rename the group. This method encompasses a few ways to update a group: 1. By + * using `add` and `remove` arrays containing phone numbers, you control the + * group movements. Any list of valid numbers in E.164 format can be added. 2. By using the + * `auto_update` object, your customer can add or remove themselves from groups. 3. You + * can also add or remove other groups into this group with `add_from_group` and + * `remove_from_group`. #### Other group update info - The request will not be rejected + * for duplicate adds or unknown removes. - The additions will be done before the deletions. If an + * phone number is on both lists, it will not be apart of the resulting group. - Updating a group + * targeted by a batch message scheduled in the future is allowed. Changes will be reflected when + * the batch is sent. + * + * @param groupId ID of a group that you are interested in getting. (required) + * @param groupUpdateRequest (optional) + * @return Group + * @throws ApiException if fails to make API call + */ + Group update(String groupId, GroupUpdateRequest groupUpdateRequest) throws ApiException; +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java new file mode 100644 index 000000000..9ffbde1dd --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java @@ -0,0 +1,50 @@ +/* + * API Overview | Sinch + * + * OpenAPI document version: v1 + * Contact: Support@sinch.com + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * Do not edit the class manually. + */ + +package com.sinch.sdk.domains.sms.api.v1; + +import com.sinch.sdk.core.exceptions.ApiException; +import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; + +public interface InboundsService { + + /** + * List incoming messages (using default parameters) With the list operation, you can list all + * inbound messages that you have received. This operation supports pagination. Inbounds are + * returned in reverse chronological order. + * + * @return ListInboundsResponse + * @throws ApiException if fails to make API call + */ + ListInboundsResponse list() throws ApiException; + + /** + * List incoming messages With the list operation, you can list all inbound messages that you have + * received. This operation supports pagination. Inbounds are returned in reverse chronological + * order. + * + * @param queryParameter (optional) + * @return ListInboundsResponse + * @throws ApiException if fails to make API call + */ + ListInboundsResponse list(ListInboundMessagesQueryParameters queryParameter) throws ApiException; + + /** + * Retrieve inbound message This operation retrieves a specific inbound message with the provided + * inbound ID. + * + * @param inboundId The inbound ID found when listing inbound messages. (required) + * @return InboundMessage + * @throws ApiException if fails to make API call + */ + InboundMessage get(String inboundId) throws ApiException; +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceImpl.java similarity index 78% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceImpl.java index dacfeb320..3cd18a999 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/BatchesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.sms.api.v1.internal; +package com.sinch.sdk.domains.sms.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; @@ -25,6 +25,7 @@ import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.models.v1.batches.request.BatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.request.DryRunQueryParameters; import com.sinch.sdk.domains.sms.models.v1.batches.request.ListBatchesQueryParameters; @@ -32,7 +33,9 @@ import com.sinch.sdk.domains.sms.models.v1.batches.request.UpdateBatchRequest; import com.sinch.sdk.domains.sms.models.v1.batches.response.BatchResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; +import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.internal.ApiBatchList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -41,17 +44,17 @@ import java.util.Map; import java.util.logging.Logger; -public class BatchesApi { +public class BatchesServiceImpl implements com.sinch.sdk.domains.sms.api.v1.BatchesService { - private static final Logger LOGGER = Logger.getLogger(BatchesApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(BatchesServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; private final String servicePlanId; - public BatchesApi( + public BatchesServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -64,18 +67,6 @@ public BatchesApi( this.servicePlanId = servicePlanId; } - /** - * Cancel a batch message A batch can be canceled at any point. If a batch is canceled while - * it's currently being delivered some messages currently being processed might still be - * delivered. The delivery report will indicate which messages were canceled and which - * weren't. Canceling a batch scheduled in the future will result in an empty delivery report - * while canceling an already sent batch would result in no change to the completed delivery - * report. - * - * @param batchId The batch ID you received from sending a message. (required) - * @return BatchResponse - * @throws ApiException if fails to make API call - */ public BatchResponse cancel(String batchId) throws ApiException { LOGGER.finest("[cancel]" + " " + "batchId: " + batchId); @@ -86,8 +77,7 @@ public BatchResponse cancel(String batchId) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -139,28 +129,11 @@ private HttpRequest cancelRequestBuilder(String batchId) throws ApiException { localVarAuthNames); } - /** - * Dry run This operation will perform a dry run of a batch which calculates the bodies and number - * of parts for all messages in the batch without actually sending any messages. - * - * @param sendRequest (optional) - * @return DryRunResponse - * @throws ApiException if fails to make API call - */ public DryRunResponse dryRun(BatchRequest sendRequest) throws ApiException { return dryRun(null, sendRequest); } - /** - * Dry run This operation will perform a dry run of a batch which calculates the bodies and number - * of parts for all messages in the batch without actually sending any messages. - * - * @param queryParameter (optional) - * @param sendRequest (optional) - * @return DryRunResponse - * @throws ApiException if fails to make API call - */ public DryRunResponse dryRun(DryRunQueryParameters queryParameter, BatchRequest sendRequest) throws ApiException { @@ -179,8 +152,7 @@ public DryRunResponse dryRun(DryRunQueryParameters queryParameter, BatchRequest this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -245,13 +217,6 @@ private HttpRequest dryRunRequestBuilder( localVarAuthNames); } - /** - * Get a batch message This operation returns a specific batch that matches the provided batch ID. - * - * @param batchId The batch ID you received from sending a message. (required) - * @return BatchResponse - * @throws ApiException if fails to make API call - */ public BatchResponse get(String batchId) throws ApiException { LOGGER.finest("[get]" + " " + "batchId: " + batchId); @@ -262,8 +227,7 @@ public BatchResponse get(String batchId) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -315,27 +279,12 @@ private HttpRequest getRequestBuilder(String batchId) throws ApiException { localVarAuthNames); } - /** - * List Batches With the list operation you can list batch messages created in the last 14 days - * that you have created. This operation supports pagination. - * - * @return ApiBatchList - * @throws ApiException if fails to make API call - */ - public ApiBatchList list() throws ApiException { + public ListBatchesResponse list() throws ApiException { return list(null); } - /** - * List Batches With the list operation you can list batch messages created in the last 14 days - * that you have created. This operation supports pagination. - * - * @param queryParameter (optional) - * @return ApiBatchList - * @throws ApiException if fails to make API call - */ - public ApiBatchList list(ListBatchesQueryParameters queryParameter) throws ApiException { + public ListBatchesResponse list(ListBatchesQueryParameters queryParameter) throws ApiException { LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); @@ -345,8 +294,16 @@ public ApiBatchList list(ListBatchesQueryParameters queryParameter) throws ApiEx this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + + ApiBatchList deserialized = + mapper.deserialize(response, new TypeReference() {}); + + return new ListBatchesResponse( + this, + new Page<>( + queryParameter, + deserialized.getItems(), + new SMSCursorPageNavigator(deserialized.getPage(), deserialized.getPageSize()))); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -433,15 +390,6 @@ private HttpRequest listRequestBuilder(ListBatchesQueryParameters queryParameter localVarAuthNames); } - /** - * Replace a batch This operation will replace all the parameters of a batch with the provided - * values. It is the same as cancelling a batch and sending a new one instead. - * - * @param batchId The batch ID you received from sending a message. (required) - * @param sendRequest (optional) - * @return BatchResponse - * @throws ApiException if fails to make API call - */ public BatchResponse replace(String batchId, BatchRequest sendRequest) throws ApiException { LOGGER.finest("[replace]" + " " + "batchId: " + batchId + ", " + "sendRequest: " + sendRequest); @@ -452,8 +400,7 @@ public BatchResponse replace(String batchId, BatchRequest sendRequest) throws Ap this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -506,21 +453,6 @@ private HttpRequest replaceRequestBuilder(String batchId, BatchRequest sendReque localVarAuthNames); } - /** - * Send delivery feedback for a message Send feedback if your system can confirm successful - * message delivery. Feedback can only be provided if `feedback_enabled` was set when - * batch was submitted. **Batches**: It is possible to submit feedback multiple times for the same - * batch for different recipients. Feedback without specified recipients is treated as successful - * message delivery to all recipients referenced in the batch. Note that the - * `recipients` key is still required even if the value is empty. **Groups**: If the - * batch message was creating using a group ID, at least one recipient is required. Excluding - * recipients (an empty recipient list) does not work and will result in a failed request. - * - * @param batchId The batch ID you received from sending a message. (required) - * @param sendDeliveryFeedbackRequest A list of phone numbers (MSISDNs) that successfully received - * the message. (required) - * @throws ApiException if fails to make API call - */ public void sendDeliveryFeedback( String batchId, SendDeliveryFeedbackRequest sendDeliveryFeedbackRequest) throws ApiException { @@ -603,17 +535,6 @@ private HttpRequest sendDeliveryFeedbackRequestBuilder( localVarAuthNames); } - /** - * Send Send a message or a batch of messages. Depending on the length of the body, one message - * might be split into multiple parts and charged accordingly. Any groups targeted in a scheduled - * batch will be evaluated at the time of sending. If a group is deleted between batch creation - * and scheduled date, it will be considered empty. Be sure to use the correct - * [region](/docs/sms/api-reference/#base-url) in the server URL. - * - * @param sendRequest Default schema is Text if type is not specified. (optional) - * @return BatchResponse - * @throws ApiException if fails to make API call - */ public BatchResponse send(BatchRequest sendRequest) throws ApiException { LOGGER.finest("[send]" + " " + "sendRequest: " + sendRequest); @@ -624,8 +545,7 @@ public BatchResponse send(BatchRequest sendRequest) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -671,15 +591,6 @@ private HttpRequest sendRequestBuilder(BatchRequest sendRequest) throws ApiExcep localVarAuthNames); } - /** - * Update a Batch message This operation updates all specified parameters of a batch that matches - * the provided batch ID. - * - * @param batchId The batch ID you received from sending a message. (required) - * @param updateBatchRequest (optional) - * @return BatchResponse - * @throws ApiException if fails to make API call - */ public BatchResponse update(String batchId, UpdateBatchRequest updateBatchRequest) throws ApiException { @@ -698,8 +609,7 @@ public BatchResponse update(String batchId, UpdateBatchRequest updateBatchReques this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceImpl.java similarity index 79% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceImpl.java index 1c3649ab4..44613b688 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/DeliveryReportsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceImpl.java @@ -8,9 +8,10 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.sms.api.v1.internal; +package com.sinch.sdk.domains.sms.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; +import com.sinch.sdk.core.databind.query_parameter.InstantToIso8601Serializer; import com.sinch.sdk.core.exceptions.ApiException; import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; import com.sinch.sdk.core.http.AuthManager; @@ -24,11 +25,14 @@ import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.BatchDeliveryReport; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.RecipientDeliveryReport; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.internal.DeliveryReportList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -37,17 +41,18 @@ import java.util.Map; import java.util.logging.Logger; -public class DeliveryReportsApi { +public class DeliveryReportsServiceImpl + implements com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService { - private static final Logger LOGGER = Logger.getLogger(DeliveryReportsApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(DeliveryReportsServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; private final String servicePlanId; - public DeliveryReportsApi( + public DeliveryReportsServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -60,32 +65,11 @@ public DeliveryReportsApi( this.servicePlanId = servicePlanId; } - /** - * Retrieve a delivery report Delivery reports can be retrieved even if no callback was requested. - * The difference between a summary and a full report is only that the full report contains the - * phone numbers in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format for - * each status code. - * - * @param batchId The batch ID you received from sending a message. (required) - * @return BatchDeliveryReport - * @throws ApiException if fails to make API call - */ public BatchDeliveryReport get(String batchId) throws ApiException { return get(batchId, null); } - /** - * Retrieve a delivery report Delivery reports can be retrieved even if no callback was requested. - * The difference between a summary and a full report is only that the full report contains the - * phone numbers in [E.164](https://community.sinch.com/t5/Glossary/E-164/ta-p/7537) format for - * each status code. - * - * @param batchId The batch ID you received from sending a message. (required) - * @param queryParameter (optional) - * @return BatchDeliveryReport - * @throws ApiException if fails to make API call - */ public BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameters queryParameter) throws ApiException { @@ -98,9 +82,7 @@ public BatchDeliveryReport get(String batchId, BatchDeliveryReportQueryParameter this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -169,15 +151,6 @@ private HttpRequest getRequestBuilder( localVarAuthNames); } - /** - * Retrieve a recipient delivery report A recipient delivery report contains the message status - * for a single recipient phone number. - * - * @param batchId The batch ID you received from sending a message. (required) - * @param recipientMsisdn Phone number for which you to want to search. (required) - * @return RecipientDeliveryReport - * @throws ApiException if fails to make API call - */ public RecipientDeliveryReport getForNumber(String batchId, String recipientMsisdn) throws ApiException { @@ -196,9 +169,7 @@ public RecipientDeliveryReport getForNumber(String batchId, String recipientMsis this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -260,27 +231,12 @@ private HttpRequest getForNumberRequestBuilder(String batchId, String recipientM localVarAuthNames); } - /** - * Retrieve a list of delivery reports Get a list of finished delivery reports. This operation - * supports pagination. - * - * @return DeliveryReportList - * @throws ApiException if fails to make API call - */ - public DeliveryReportList list() throws ApiException { + public ListDeliveryReportsResponse list() throws ApiException { return list(null); } - /** - * Retrieve a list of delivery reports Get a list of finished delivery reports. This operation - * supports pagination. - * - * @param queryParameter (optional) - * @return DeliveryReportList - * @throws ApiException if fails to make API call - */ - public DeliveryReportList list(ListDeliveryReportsQueryParameters queryParameter) + public ListDeliveryReportsResponse list(ListDeliveryReportsQueryParameters queryParameter) throws ApiException { LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); @@ -291,9 +247,16 @@ public DeliveryReportList list(ListDeliveryReportsQueryParameters queryParameter this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = - new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + + DeliveryReportList deserialized = + mapper.deserialize(response, new TypeReference() {}); + + return new ListDeliveryReportsResponse( + this, + new Page<>( + queryParameter, + deserialized.getItems(), + new SMSCursorPageNavigator(deserialized.getPage(), deserialized.getPageSize()))); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -336,7 +299,7 @@ private HttpRequest listRequestBuilder(ListDeliveryReportsQueryParameters queryP queryParameter.getStartDate(), "start_date", URLParameter.form, - null, + InstantToIso8601Serializer.getInstance(), localVarQueryParams, true); @@ -344,7 +307,7 @@ private HttpRequest listRequestBuilder(ListDeliveryReportsQueryParameters queryP queryParameter.getEndDate(), "end_date", URLParameter.form, - null, + InstantToIso8601Serializer.getInstance(), localVarQueryParams, true); diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceImpl.java similarity index 65% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceImpl.java index 4ff46673d..3c2f2107d 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/GroupsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.sms.api.v1.internal; +package com.sinch.sdk.domains.sms.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.exceptions.ApiException; @@ -24,11 +24,14 @@ import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.models.v1.groups.Group; import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupRequest; import com.sinch.sdk.domains.sms.models.v1.groups.request.GroupUpdateRequest; import com.sinch.sdk.domains.sms.models.v1.groups.request.ListGroupsQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; import com.sinch.sdk.domains.sms.models.v1.groups.response.internal.ApiGroupList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -37,17 +40,17 @@ import java.util.Map; import java.util.logging.Logger; -public class GroupsApi { +public class GroupsServiceImpl implements com.sinch.sdk.domains.sms.api.v1.GroupsService { - private static final Logger LOGGER = Logger.getLogger(GroupsApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(GroupsServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; private final String servicePlanId; - public GroupsApi( + public GroupsServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -60,32 +63,17 @@ public GroupsApi( this.servicePlanId = servicePlanId; } - /** - * Create a group This endpoint allows you to create a group of recipients. A new group must be - * created with a group name. This is represented by the `name` field which can be up to - * 20 charecters. In addition, there are a number of optional fields: - `members` field - * enables groups to be created with an initial list of contacts - `auto_update` allows - * customers to auto subscribe to a new group. This contains three fields. The `to` - * field contains the group creator's number. (This number **must be provisioned by contacting - * your account manager**.) The `add` and `remove` fields are objects - * containing the keywords that customers need to text to join or leave a group. - * - * @param groupRequest (optional) - * @return Group - * @throws ApiException if fails to make API call - */ - public Group createGroup(GroupRequest groupRequest) throws ApiException { - - LOGGER.finest("[createGroup]" + " " + "groupRequest: " + groupRequest); - - HttpRequest httpRequest = createGroupRequestBuilder(groupRequest); + public Group create(GroupRequest groupRequest) throws ApiException { + + LOGGER.finest("[create]" + " " + "groupRequest: " + groupRequest); + + HttpRequest httpRequest = createRequestBuilder(groupRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -96,11 +84,11 @@ public Group createGroup(GroupRequest groupRequest) throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest createGroupRequestBuilder(GroupRequest groupRequest) throws ApiException { + private HttpRequest createRequestBuilder(GroupRequest groupRequest) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling createGroup"); + 400, "Missing the required parameter 'this.servicePlanId' when calling create"); } String localVarPath = @@ -131,17 +119,11 @@ private HttpRequest createGroupRequestBuilder(GroupRequest groupRequest) throws localVarAuthNames); } - /** - * Delete a group This operation deletes the group with the provided group ID. - * - * @param groupId ID of a group that you are interested in getting. (required) - * @throws ApiException if fails to make API call - */ - public void deleteGroup(String groupId) throws ApiException { + public void delete(String groupId) throws ApiException { - LOGGER.finest("[deleteGroup]" + " " + "groupId: " + groupId); + LOGGER.finest("[delete]" + " " + "groupId: " + groupId); - HttpRequest httpRequest = deleteGroupRequestBuilder(groupId); + HttpRequest httpRequest = deleteRequestBuilder(groupId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); @@ -158,16 +140,15 @@ public void deleteGroup(String groupId) throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest deleteGroupRequestBuilder(String groupId) throws ApiException { + private HttpRequest deleteRequestBuilder(String groupId) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling deleteGroup"); + 400, "Missing the required parameter 'this.servicePlanId' when calling delete"); } // verify the required parameter 'groupId' is set if (groupId == null) { - throw new ApiException( - 400, "Missing the required parameter 'groupId' when calling deleteGroup"); + throw new ApiException(400, "Missing the required parameter 'groupId' when calling delete"); } String localVarPath = @@ -200,26 +181,17 @@ private HttpRequest deleteGroupRequestBuilder(String groupId) throws ApiExceptio localVarAuthNames); } - /** - * Get phone numbers for a group This operation retrieves the members of the group with the - * provided group ID. - * - * @param groupId ID of a group that you are interested in getting. (required) - * @return List<String> - * @throws ApiException if fails to make API call - */ - public List getMembers(String groupId) throws ApiException { + public List listMembers(String groupId) throws ApiException { - LOGGER.finest("[getMembers]" + " " + "groupId: " + groupId); + LOGGER.finest("[listMembers]" + " " + "groupId: " + groupId); - HttpRequest httpRequest = getMembersRequestBuilder(groupId); + HttpRequest httpRequest = listMembersRequestBuilder(groupId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference> localVarReturnType = new TypeReference>() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference>() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -230,16 +202,16 @@ public List getMembers(String groupId) throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest getMembersRequestBuilder(String groupId) throws ApiException { + private HttpRequest listMembersRequestBuilder(String groupId) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling getMembers"); + 400, "Missing the required parameter 'this.servicePlanId' when calling listMembers"); } // verify the required parameter 'groupId' is set if (groupId == null) { throw new ApiException( - 400, "Missing the required parameter 'groupId' when calling getMembers"); + 400, "Missing the required parameter 'groupId' when calling listMembers"); } String localVarPath = @@ -272,38 +244,31 @@ private HttpRequest getMembersRequestBuilder(String groupId) throws ApiException localVarAuthNames); } - /** - * List Groups With the list operation you can list all groups that you have created. This - * operation supports pagination. Groups are returned in reverse chronological order. - * - * @return ApiGroupList - * @throws ApiException if fails to make API call - */ - public ApiGroupList listGroups() throws ApiException { + public ListGroupsResponse list() throws ApiException { - return listGroups(null); + return list(null); } - /** - * List Groups With the list operation you can list all groups that you have created. This - * operation supports pagination. Groups are returned in reverse chronological order. - * - * @param queryParameter (optional) - * @return ApiGroupList - * @throws ApiException if fails to make API call - */ - public ApiGroupList listGroups(ListGroupsQueryParameters queryParameter) throws ApiException { + public ListGroupsResponse list(ListGroupsQueryParameters queryParameter) throws ApiException { - LOGGER.finest("[listGroups]" + " " + "queryParameter: " + queryParameter); + LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); - HttpRequest httpRequest = listGroupsRequestBuilder(queryParameter); + HttpRequest httpRequest = listRequestBuilder(queryParameter); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + + ApiGroupList deserialized = + mapper.deserialize(response, new TypeReference() {}); + + return new ListGroupsResponse( + this, + new Page<>( + queryParameter, + deserialized.getItems(), + new SMSCursorPageNavigator(deserialized.getPage(), deserialized.getPageSize()))); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -314,12 +279,12 @@ public ApiGroupList listGroups(ListGroupsQueryParameters queryParameter) throws mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest listGroupsRequestBuilder(ListGroupsQueryParameters queryParameter) + private HttpRequest listRequestBuilder(ListGroupsQueryParameters queryParameter) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling listGroups"); + 400, "Missing the required parameter 'this.servicePlanId' when calling list"); } String localVarPath = @@ -363,29 +328,18 @@ private HttpRequest listGroupsRequestBuilder(ListGroupsQueryParameters queryPara localVarAuthNames); } - /** - * Replace a group The replace operation will replace all parameters, including members, of an - * existing group with new values. Replacing a group targeted by a batch message scheduled in the - * future is allowed and changes will be reflected when the batch is sent. - * - * @param groupId ID of a group that you are interested in getting. (required) - * @param groupRequest (optional) - * @return Group - * @throws ApiException if fails to make API call - */ - public Group replaceGroup(String groupId, GroupRequest groupRequest) throws ApiException { + public Group replace(String groupId, GroupRequest groupRequest) throws ApiException { LOGGER.finest( - "[replaceGroup]" + " " + "groupId: " + groupId + ", " + "groupRequest: " + groupRequest); + "[replace]" + " " + "groupId: " + groupId + ", " + "groupRequest: " + groupRequest); - HttpRequest httpRequest = replaceGroupRequestBuilder(groupId, groupRequest); + HttpRequest httpRequest = replaceRequestBuilder(groupId, groupRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -396,17 +350,16 @@ public Group replaceGroup(String groupId, GroupRequest groupRequest) throws ApiE mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest replaceGroupRequestBuilder(String groupId, GroupRequest groupRequest) + private HttpRequest replaceRequestBuilder(String groupId, GroupRequest groupRequest) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling replaceGroup"); + 400, "Missing the required parameter 'this.servicePlanId' when calling replace"); } // verify the required parameter 'groupId' is set if (groupId == null) { - throw new ApiException( - 400, "Missing the required parameter 'groupId' when calling replaceGroup"); + throw new ApiException(400, "Missing the required parameter 'groupId' when calling replace"); } String localVarPath = @@ -439,25 +392,17 @@ private HttpRequest replaceGroupRequestBuilder(String groupId, GroupRequest grou localVarAuthNames); } - /** - * Retrieve a group This operation retrieves a specific group with the provided group ID. - * - * @param groupId ID of a group that you are interested in getting. (required) - * @return Group - * @throws ApiException if fails to make API call - */ - public Group retrieveGroup(String groupId) throws ApiException { + public Group get(String groupId) throws ApiException { - LOGGER.finest("[retrieveGroup]" + " " + "groupId: " + groupId); + LOGGER.finest("[get]" + " " + "groupId: " + groupId); - HttpRequest httpRequest = retrieveGroupRequestBuilder(groupId); + HttpRequest httpRequest = getRequestBuilder(groupId); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -468,16 +413,15 @@ public Group retrieveGroup(String groupId) throws ApiException { mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest retrieveGroupRequestBuilder(String groupId) throws ApiException { + private HttpRequest getRequestBuilder(String groupId) throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling retrieveGroup"); + 400, "Missing the required parameter 'this.servicePlanId' when calling get"); } // verify the required parameter 'groupId' is set if (groupId == null) { - throw new ApiException( - 400, "Missing the required parameter 'groupId' when calling retrieveGroup"); + throw new ApiException(400, "Missing the required parameter 'groupId' when calling get"); } String localVarPath = @@ -510,29 +454,10 @@ private HttpRequest retrieveGroupRequestBuilder(String groupId) throws ApiExcept localVarAuthNames); } - /** - * Update a group With the update group operation, you can add and remove members in an existing - * group as well as rename the group. This method encompasses a few ways to update a group: 1. By - * using `add` and `remove` arrays containing phone numbers, you control the - * group movements. Any list of valid numbers in E.164 format can be added. 2. By using the - * `auto_update` object, your customer can add or remove themselves from groups. 3. You - * can also add or remove other groups into this group with `add_from_group` and - * `remove_from_group`. #### Other group update info - The request will not be rejected - * for duplicate adds or unknown removes. - The additions will be done before the deletions. If an - * phone number is on both lists, it will not be apart of the resulting group. - Updating a group - * targeted by a batch message scheduled in the future is allowed. Changes will be reflected when - * the batch is sent. - * - * @param groupId ID of a group that you are interested in getting. (required) - * @param groupUpdateRequest (optional) - * @return Group - * @throws ApiException if fails to make API call - */ - public Group updateGroup(String groupId, GroupUpdateRequest groupUpdateRequest) - throws ApiException { + public Group update(String groupId, GroupUpdateRequest groupUpdateRequest) throws ApiException { LOGGER.finest( - "[updateGroup]" + "[update]" + " " + "groupId: " + groupId @@ -540,14 +465,13 @@ public Group updateGroup(String groupId, GroupUpdateRequest groupUpdateRequest) + "groupUpdateRequest: " + groupUpdateRequest); - HttpRequest httpRequest = updateGroupRequestBuilder(groupId, groupUpdateRequest); + HttpRequest httpRequest = updateRequestBuilder(groupId, groupUpdateRequest); HttpResponse response = httpClient.invokeAPI( this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -558,17 +482,16 @@ public Group updateGroup(String groupId, GroupUpdateRequest groupUpdateRequest) mapper.deserialize(response, new TypeReference>() {})); } - private HttpRequest updateGroupRequestBuilder( - String groupId, GroupUpdateRequest groupUpdateRequest) throws ApiException { + private HttpRequest updateRequestBuilder(String groupId, GroupUpdateRequest groupUpdateRequest) + throws ApiException { // verify the required parameter 'this.servicePlanId' is set if (this.servicePlanId == null) { throw new ApiException( - 400, "Missing the required parameter 'this.servicePlanId' when calling updateGroup"); + 400, "Missing the required parameter 'this.servicePlanId' when calling update"); } // verify the required parameter 'groupId' is set if (groupId == null) { - throw new ApiException( - 400, "Missing the required parameter 'groupId' when calling updateGroup"); + throw new ApiException(400, "Missing the required parameter 'groupId' when calling update"); } String localVarPath = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceImpl.java similarity index 81% rename from openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java rename to openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceImpl.java index b47b57771..af85db19f 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/internal/InboundsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceImpl.java @@ -8,7 +8,7 @@ * Do not edit the class manually. */ -package com.sinch.sdk.domains.sms.api.v1.internal; +package com.sinch.sdk.domains.sms.api.v1.adapters; import com.fasterxml.jackson.core.type.TypeReference; import com.sinch.sdk.core.databind.query_parameter.CollectionStringToCommaSerializer; @@ -26,9 +26,12 @@ import com.sinch.sdk.core.http.URLParameterUtils; import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.core.models.pagination.Page; import com.sinch.sdk.domains.sms.models.v1.inbounds.InboundMessage; import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; +import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.ApiInboundList; +import com.sinch.sdk.domains.sms.models.v1.internal.SMSCursorPageNavigator; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -37,17 +40,17 @@ import java.util.Map; import java.util.logging.Logger; -public class InboundsApi { +public class InboundsServiceImpl implements com.sinch.sdk.domains.sms.api.v1.InboundsService { - private static final Logger LOGGER = Logger.getLogger(InboundsApi.class.getName()); - private HttpClient httpClient; - private ServerConfiguration serverConfiguration; - private Map authManagersByOasSecuritySchemes; - private HttpMapper mapper; + private static final Logger LOGGER = Logger.getLogger(InboundsServiceImpl.class.getName()); + private final HttpClient httpClient; + private final ServerConfiguration serverConfiguration; + private final Map authManagersByOasSecuritySchemes; + private final HttpMapper mapper; private final String servicePlanId; - public InboundsApi( + public InboundsServiceImpl( HttpClient httpClient, ServerConfiguration serverConfiguration, Map authManagersByOasSecuritySchemes, @@ -60,29 +63,12 @@ public InboundsApi( this.servicePlanId = servicePlanId; } - /** - * List incoming messages With the list operation, you can list all inbound messages that you have - * received. This operation supports pagination. Inbounds are returned in reverse chronological - * order. - * - * @return ApiInboundList - * @throws ApiException if fails to make API call - */ - public ApiInboundList list() throws ApiException { + public ListInboundsResponse list() throws ApiException { return list(null); } - /** - * List incoming messages With the list operation, you can list all inbound messages that you have - * received. This operation supports pagination. Inbounds are returned in reverse chronological - * order. - * - * @param queryParameter (optional) - * @return ApiInboundList - * @throws ApiException if fails to make API call - */ - public ApiInboundList list(ListInboundMessagesQueryParameters queryParameter) + public ListInboundsResponse list(ListInboundMessagesQueryParameters queryParameter) throws ApiException { LOGGER.finest("[list]" + " " + "queryParameter: " + queryParameter); @@ -93,8 +79,16 @@ public ApiInboundList list(ListInboundMessagesQueryParameters queryParameter) this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + + ApiInboundList deserialized = + mapper.deserialize(response, new TypeReference() {}); + + return new ListInboundsResponse( + this, + new Page<>( + queryParameter, + deserialized.getItems(), + new SMSCursorPageNavigator(deserialized.getPage(), deserialized.getPageSize()))); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content @@ -186,14 +180,6 @@ private HttpRequest listRequestBuilder(ListInboundMessagesQueryParameters queryP localVarAuthNames); } - /** - * Retrieve inbound message This operation retrieves a specific inbound message with the provided - * inbound ID. - * - * @param inboundId The inbound ID found when listing inbound messages. (required) - * @return InboundMessage - * @throws ApiException if fails to make API call - */ public InboundMessage get(String inboundId) throws ApiException { LOGGER.finest("[get]" + " " + "inboundId: " + inboundId); @@ -204,8 +190,7 @@ public InboundMessage get(String inboundId) throws ApiException { this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); if (HttpStatus.isSuccessfulStatus(response.getCode())) { - TypeReference localVarReturnType = new TypeReference() {}; - return mapper.deserialize(response, localVarReturnType); + return mapper.deserialize(response, new TypeReference() {}); } // fallback to default errors handling: // all error cases definition are not required from specs: will try some "hardcoded" content diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java index 695ce3e06..4614669ab 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchList.java @@ -35,9 +35,9 @@ public interface ApiBatchList { /** * The page of batches matching the given filters. * - * @return batches + * @return items */ - List getBatches(); + List getItems(); /** * The number of entries returned in this request. @@ -79,11 +79,11 @@ interface Builder { /** * see getter * - * @param batches see getter + * @param items see getter * @return Current builder - * @see #getBatches + * @see #getItems */ - Builder setBatches(List batches); + Builder setItems(List items); /** * see getter diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java index 24da89567..2b133dfce 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/internal/ApiBatchListImpl.java @@ -32,7 +32,7 @@ public class ApiBatchListImpl implements ApiBatchList { public static final String JSON_PROPERTY_BATCHES = "batches"; - private OptionalValue> batches; + private OptionalValue> items; public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; @@ -43,11 +43,11 @@ public ApiBatchListImpl() {} protected ApiBatchListImpl( OptionalValue count, OptionalValue page, - OptionalValue> batches, + OptionalValue> items, OptionalValue pageSize) { this.count = count; this.page = page; - this.batches = batches; + this.items = items; this.pageSize = pageSize; } @@ -74,14 +74,14 @@ public OptionalValue page() { } @JsonIgnore - public List getBatches() { - return batches.orElse(null); + public List getItems() { + return items.orElse(null); } @JsonProperty(JSON_PROPERTY_BATCHES) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue> batches() { - return batches; + public OptionalValue> items() { + return items; } @JsonIgnore @@ -107,13 +107,13 @@ public boolean equals(Object o) { ApiBatchListImpl apiBatchList = (ApiBatchListImpl) o; return Objects.equals(this.count, apiBatchList.count) && Objects.equals(this.page, apiBatchList.page) - && Objects.equals(this.batches, apiBatchList.batches) + && Objects.equals(this.items, apiBatchList.items) && Objects.equals(this.pageSize, apiBatchList.pageSize); } @Override public int hashCode() { - return Objects.hash(count, page, batches, pageSize); + return Objects.hash(count, page, items, pageSize); } @Override @@ -122,7 +122,7 @@ public String toString() { sb.append("class ApiBatchListImpl {\n"); sb.append(" count: ").append(toIndentedString(count)).append("\n"); sb.append(" page: ").append(toIndentedString(page)).append("\n"); - sb.append(" batches: ").append(toIndentedString(batches)).append("\n"); + sb.append(" items: ").append(toIndentedString(items)).append("\n"); sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); sb.append("}"); return sb.toString(); @@ -142,7 +142,7 @@ private String toIndentedString(Object o) { static class Builder implements ApiBatchList.Builder { OptionalValue count = OptionalValue.empty(); OptionalValue page = OptionalValue.empty(); - OptionalValue> batches = OptionalValue.empty(); + OptionalValue> items = OptionalValue.empty(); OptionalValue pageSize = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_COUNT) @@ -158,8 +158,8 @@ public Builder setPage(Integer page) { } @JsonProperty(JSON_PROPERTY_BATCHES) - public Builder setBatches(List batches) { - this.batches = OptionalValue.of(batches); + public Builder setItems(List items) { + this.items = OptionalValue.of(items); return this; } @@ -170,7 +170,7 @@ public Builder setPageSize(Integer pageSize) { } public ApiBatchList build() { - return new ApiBatchListImpl(count, page, batches, pageSize); + return new ApiBatchListImpl(count, page, items, pageSize); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java index 9fcb56fe2..91395a4bb 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportList.java @@ -42,9 +42,9 @@ public interface DeliveryReportList { /** * The page of delivery reports matching the given filters. * - * @return deliveryReports + * @return items */ - List getDeliveryReports(); + List getItems(); /** * Getting builder @@ -88,11 +88,11 @@ interface Builder { /** * see getter * - * @param deliveryReports see getter + * @param items see getter * @return Current builder - * @see #getDeliveryReports + * @see #getItems */ - Builder setDeliveryReports(List deliveryReports); + Builder setItems(List items); /** * Create instance diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java index d84a1e029..1dbfb3d06 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/internal/DeliveryReportListImpl.java @@ -36,7 +36,7 @@ public class DeliveryReportListImpl implements DeliveryReportList { public static final String JSON_PROPERTY_DELIVERY_REPORTS = "delivery_reports"; - private OptionalValue> deliveryReports; + private OptionalValue> items; public DeliveryReportListImpl() {} @@ -44,11 +44,11 @@ protected DeliveryReportListImpl( OptionalValue count, OptionalValue page, OptionalValue pageSize, - OptionalValue> deliveryReports) { + OptionalValue> items) { this.count = count; this.page = page; this.pageSize = pageSize; - this.deliveryReports = deliveryReports; + this.items = items; } @JsonIgnore @@ -85,14 +85,14 @@ public OptionalValue pageSize() { } @JsonIgnore - public List getDeliveryReports() { - return deliveryReports.orElse(null); + public List getItems() { + return items.orElse(null); } @JsonProperty(JSON_PROPERTY_DELIVERY_REPORTS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue> deliveryReports() { - return deliveryReports; + public OptionalValue> items() { + return items; } /** Return true if this DeliveryReportList object is equal to o. */ @@ -108,12 +108,12 @@ public boolean equals(Object o) { return Objects.equals(this.count, deliveryReportList.count) && Objects.equals(this.page, deliveryReportList.page) && Objects.equals(this.pageSize, deliveryReportList.pageSize) - && Objects.equals(this.deliveryReports, deliveryReportList.deliveryReports); + && Objects.equals(this.items, deliveryReportList.items); } @Override public int hashCode() { - return Objects.hash(count, page, pageSize, deliveryReports); + return Objects.hash(count, page, pageSize, items); } @Override @@ -123,7 +123,7 @@ public String toString() { sb.append(" count: ").append(toIndentedString(count)).append("\n"); sb.append(" page: ").append(toIndentedString(page)).append("\n"); sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); - sb.append(" deliveryReports: ").append(toIndentedString(deliveryReports)).append("\n"); + sb.append(" items: ").append(toIndentedString(items)).append("\n"); sb.append("}"); return sb.toString(); } @@ -143,7 +143,7 @@ static class Builder implements DeliveryReportList.Builder { OptionalValue count = OptionalValue.empty(); OptionalValue page = OptionalValue.empty(); OptionalValue pageSize = OptionalValue.empty(); - OptionalValue> deliveryReports = OptionalValue.empty(); + OptionalValue> items = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_COUNT) public Builder setCount(Long count) { @@ -164,13 +164,13 @@ public Builder setPageSize(Integer pageSize) { } @JsonProperty(JSON_PROPERTY_DELIVERY_REPORTS) - public Builder setDeliveryReports(List deliveryReports) { - this.deliveryReports = OptionalValue.of(deliveryReports); + public Builder setItems(List items) { + this.items = OptionalValue.of(items); return this; } public DeliveryReportList build() { - return new DeliveryReportListImpl(count, page, pageSize, deliveryReports); + return new DeliveryReportListImpl(count, page, pageSize, items); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java index 5a0191d7b..ffec32daa 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupList.java @@ -40,11 +40,11 @@ public interface ApiGroupList { Integer getCount(); /** - * Get groups + * Get items * - * @return groups + * @return items */ - List getGroups(); + List getItems(); /** * Getting builder @@ -88,11 +88,11 @@ interface Builder { /** * see getter * - * @param groups see getter + * @param items see getter * @return Current builder - * @see #getGroups + * @see #getItems */ - Builder setGroups(List groups); + Builder setItems(List items); /** * Create instance diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java index 89355628c..59559c616 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/internal/ApiGroupListImpl.java @@ -36,7 +36,7 @@ public class ApiGroupListImpl implements ApiGroupList { public static final String JSON_PROPERTY_GROUPS = "groups"; - private OptionalValue> groups; + private OptionalValue> items; public ApiGroupListImpl() {} @@ -44,11 +44,11 @@ protected ApiGroupListImpl( OptionalValue page, OptionalValue pageSize, OptionalValue count, - OptionalValue> groups) { + OptionalValue> items) { this.page = page; this.pageSize = pageSize; this.count = count; - this.groups = groups; + this.items = items; } @JsonIgnore @@ -85,14 +85,14 @@ public OptionalValue count() { } @JsonIgnore - public List getGroups() { - return groups.orElse(null); + public List getItems() { + return items.orElse(null); } @JsonProperty(JSON_PROPERTY_GROUPS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue> groups() { - return groups; + public OptionalValue> items() { + return items; } /** Return true if this ApiGroupList object is equal to o. */ @@ -108,12 +108,12 @@ public boolean equals(Object o) { return Objects.equals(this.page, apiGroupList.page) && Objects.equals(this.pageSize, apiGroupList.pageSize) && Objects.equals(this.count, apiGroupList.count) - && Objects.equals(this.groups, apiGroupList.groups); + && Objects.equals(this.items, apiGroupList.items); } @Override public int hashCode() { - return Objects.hash(page, pageSize, count, groups); + return Objects.hash(page, pageSize, count, items); } @Override @@ -123,7 +123,7 @@ public String toString() { sb.append(" page: ").append(toIndentedString(page)).append("\n"); sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); sb.append(" count: ").append(toIndentedString(count)).append("\n"); - sb.append(" groups: ").append(toIndentedString(groups)).append("\n"); + sb.append(" items: ").append(toIndentedString(items)).append("\n"); sb.append("}"); return sb.toString(); } @@ -143,7 +143,7 @@ static class Builder implements ApiGroupList.Builder { OptionalValue page = OptionalValue.empty(); OptionalValue pageSize = OptionalValue.empty(); OptionalValue count = OptionalValue.empty(); - OptionalValue> groups = OptionalValue.empty(); + OptionalValue> items = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_PAGE) public Builder setPage(Integer page) { @@ -164,13 +164,13 @@ public Builder setCount(Integer count) { } @JsonProperty(JSON_PROPERTY_GROUPS) - public Builder setGroups(List groups) { - this.groups = OptionalValue.of(groups); + public Builder setItems(List items) { + this.items = OptionalValue.of(items); return this; } public ApiGroupList build() { - return new ApiGroupListImpl(page, pageSize, count, groups); + return new ApiGroupListImpl(page, pageSize, count, items); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java index 0f8d61df9..211004867 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundList.java @@ -35,9 +35,9 @@ public interface ApiInboundList { /** * The page of inbounds matching the given filters. * - * @return inbounds + * @return items */ - List getInbounds(); + List getItems(); /** * The number of inbounds returned in this request. @@ -79,11 +79,11 @@ interface Builder { /** * see getter * - * @param inbounds see getter + * @param items see getter * @return Current builder - * @see #getInbounds + * @see #getItems */ - Builder setInbounds(List inbounds); + Builder setItems(List items); /** * see getter diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java index f1068f116..6f5fd51a1 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/internal/ApiInboundListImpl.java @@ -32,7 +32,7 @@ public class ApiInboundListImpl implements ApiInboundList { public static final String JSON_PROPERTY_INBOUNDS = "inbounds"; - private OptionalValue> inbounds; + private OptionalValue> items; public static final String JSON_PROPERTY_PAGE_SIZE = "page_size"; @@ -43,11 +43,11 @@ public ApiInboundListImpl() {} protected ApiInboundListImpl( OptionalValue count, OptionalValue page, - OptionalValue> inbounds, + OptionalValue> items, OptionalValue pageSize) { this.count = count; this.page = page; - this.inbounds = inbounds; + this.items = items; this.pageSize = pageSize; } @@ -74,14 +74,14 @@ public OptionalValue page() { } @JsonIgnore - public List getInbounds() { - return inbounds.orElse(null); + public List getItems() { + return items.orElse(null); } @JsonProperty(JSON_PROPERTY_INBOUNDS) @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) - public OptionalValue> inbounds() { - return inbounds; + public OptionalValue> items() { + return items; } @JsonIgnore @@ -107,13 +107,13 @@ public boolean equals(Object o) { ApiInboundListImpl apiInboundList = (ApiInboundListImpl) o; return Objects.equals(this.count, apiInboundList.count) && Objects.equals(this.page, apiInboundList.page) - && Objects.equals(this.inbounds, apiInboundList.inbounds) + && Objects.equals(this.items, apiInboundList.items) && Objects.equals(this.pageSize, apiInboundList.pageSize); } @Override public int hashCode() { - return Objects.hash(count, page, inbounds, pageSize); + return Objects.hash(count, page, items, pageSize); } @Override @@ -122,7 +122,7 @@ public String toString() { sb.append("class ApiInboundListImpl {\n"); sb.append(" count: ").append(toIndentedString(count)).append("\n"); sb.append(" page: ").append(toIndentedString(page)).append("\n"); - sb.append(" inbounds: ").append(toIndentedString(inbounds)).append("\n"); + sb.append(" items: ").append(toIndentedString(items)).append("\n"); sb.append(" pageSize: ").append(toIndentedString(pageSize)).append("\n"); sb.append("}"); return sb.toString(); @@ -142,7 +142,7 @@ private String toIndentedString(Object o) { static class Builder implements ApiInboundList.Builder { OptionalValue count = OptionalValue.empty(); OptionalValue page = OptionalValue.empty(); - OptionalValue> inbounds = OptionalValue.empty(); + OptionalValue> items = OptionalValue.empty(); OptionalValue pageSize = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_COUNT) @@ -158,8 +158,8 @@ public Builder setPage(Integer page) { } @JsonProperty(JSON_PROPERTY_INBOUNDS) - public Builder setInbounds(List inbounds) { - this.inbounds = OptionalValue.of(inbounds); + public Builder setItems(List items) { + this.items = OptionalValue.of(items); return this; } @@ -170,7 +170,7 @@ public Builder setPageSize(Integer pageSize) { } public ApiInboundList build() { - return new ApiInboundListImpl(count, page, inbounds, pageSize); + return new ApiInboundListImpl(count, page, items, pageSize); } } } From c8b0093e1a8dc9bbf2b14f3ed4136f3c7fe3a933 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Sat, 18 Jan 2025 16:28:54 +0100 Subject: [PATCH 56/65] test (SMS): Use 'URLPathUtils.encodePathSegment' from tests --- .../api/v1/adapters/BatchesServiceTest.java | 60 +++++++++++++------ .../adapters/DeliveryReportsServiceTest.java | 34 ++++++++--- .../api/v1/adapters/GroupsServiceTest.java | 56 ++++++++++++----- .../api/v1/adapters/InboundsServiceTest.java | 24 +++++--- 4 files changed, 124 insertions(+), 50 deletions(-) diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java index be89d7e97..7f9a372ee 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/BatchesServiceTest.java @@ -20,6 +20,7 @@ import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.PaginationFillerHelper; import com.sinch.sdk.domains.sms.api.v1.BatchesService; @@ -49,6 +50,9 @@ public class BatchesServiceTest extends BaseTest { static final String SMS_AUTH_NAMES = "BearerAuth"; + static final String SERVICE_PLAN_ID = "foo value"; + static final String BATCH_ID = "foo batchID"; + @GivenJsonResource("/domains/sms/v1/batches/request/TextRequestDto.json") TextRequest textRequestDto; @@ -95,7 +99,11 @@ public class BatchesServiceTest extends BaseTest { public void initMocks() { service = new BatchesServiceImpl( - httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); + httpClient, + serverConfiguration, + authManagers, + HttpMapper.getInstance(), + SERVICE_PLAN_ID); } @Test @@ -103,7 +111,10 @@ void get() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20binary%20batch%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID), HttpMethod.GET, Collections.emptyList(), null, @@ -120,7 +131,7 @@ void get() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - BatchResponse response = service.get("foo binary batch id"); + BatchResponse response = service.get(BATCH_ID); TestHelpers.recursiveEquals(response, textResponseDto); } @@ -130,7 +141,7 @@ void send() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches", HttpMethod.POST, Collections.emptyList(), HttpMapper.getInstance() @@ -159,7 +170,7 @@ void dryRunDefault() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/dry_run", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches/dry_run", HttpMethod.POST, Collections.emptyList(), HttpMapper.getInstance() @@ -196,7 +207,7 @@ void dryRun() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/dry_run", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches/dry_run", HttpMethod.POST, urlParameters, HttpMapper.getInstance() @@ -225,7 +236,7 @@ void listDefault() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches", HttpMethod.GET, Collections.emptyList(), null, @@ -282,7 +293,7 @@ void list() throws ApiException { HttpRequest httpRequest0 = new HttpRequest( - "/xms/v1/foovalue/batches", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches", HttpMethod.GET, urlParametersPage0, null, @@ -293,7 +304,7 @@ void list() throws ApiException { HttpRequest httpRequest1 = new HttpRequest( - "/xms/v1/foovalue/batches", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches", HttpMethod.GET, urlParametersPage1, null, @@ -304,7 +315,7 @@ void list() throws ApiException { HttpRequest httpRequest2 = new HttpRequest( - "/xms/v1/foovalue/batches", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/batches", HttpMethod.GET, urlParametersPage2, null, @@ -371,7 +382,10 @@ void update() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID), HttpMethod.POST, Collections.emptyList(), HttpMapper.getInstance() @@ -391,7 +405,7 @@ void update() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - BatchResponse response = service.update("foo text batch id", updateTextRequestDto); + BatchResponse response = service.update(BATCH_ID, updateTextRequestDto); TestHelpers.recursiveEquals(response, textResponseDto); } @@ -401,7 +415,10 @@ void replace() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID), HttpMethod.PUT, Collections.emptyList(), HttpMapper.getInstance() @@ -420,7 +437,7 @@ void replace() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - BatchResponse response = service.replace("foo text batch id", textRequestDto); + BatchResponse response = service.replace(BATCH_ID, textRequestDto); TestHelpers.recursiveEquals(response, textResponseDto); } @@ -430,7 +447,10 @@ void cancel() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID), HttpMethod.DELETE, Collections.emptyList(), null, @@ -447,7 +467,7 @@ void cancel() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - BatchResponse response = service.cancel("foo text batch id"); + BatchResponse response = service.cancel(BATCH_ID); TestHelpers.recursiveEquals(response, textResponseDto); } @@ -457,7 +477,11 @@ void sendDeliveryFeedback() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20text%20batch%20id/delivery_feedback", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID) + + "/delivery_feedback", HttpMethod.POST, Collections.emptyList(), HttpMapper.getInstance() @@ -476,6 +500,6 @@ void sendDeliveryFeedback() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - service.sendDeliveryFeedback("foo text batch id", sendDeliveryFeedbackRequestDto); + service.sendDeliveryFeedback(BATCH_ID, sendDeliveryFeedbackRequestDto); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java index d040097c6..8c4562c55 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/DeliveryReportsServiceTest.java @@ -20,6 +20,7 @@ import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.PaginationFillerHelper; import com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService; @@ -45,6 +46,8 @@ @TestWithResources class DeliveryReportsServiceTest extends BaseTest { static final String SMS_AUTH_NAMES = "BearerAuth"; + static final String SERVICE_PLAN_ID = "foo value"; + static final String BATCH_ID = "foo batchID"; @GivenTextResource("/domains/sms/v1/deliveryreports/BatchDeliveryReportSMSDto.json") String jsonBatchDeliveryReportSMSDto; @@ -88,7 +91,11 @@ class DeliveryReportsServiceTest extends BaseTest { public void initMocks() { service = new DeliveryReportsServiceImpl( - httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); + httpClient, + serverConfiguration, + authManagers, + HttpMapper.getInstance(), + SERVICE_PLAN_ID); } @Test @@ -96,7 +103,11 @@ void getBatchDeliveryReport() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20binary%20batch%20id/delivery_report", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID) + + "/delivery_report", HttpMethod.GET, Collections.emptyList(), null, @@ -114,7 +125,7 @@ void getBatchDeliveryReport() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - BatchDeliveryReport response = service.get("foo binary batch id"); + BatchDeliveryReport response = service.get(BATCH_ID); TestHelpers.recursiveEquals(response, batchDeliveryReportSMSDto); } @@ -124,7 +135,12 @@ void getRecipientDeliveryReport() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/batches/foo%20binary%20batch%20id/delivery_report/foo%20number", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/batches/" + + URLPathUtils.encodePathSegment(BATCH_ID) + + "/delivery_report/" + + URLPathUtils.encodePathSegment("+1234567890"), HttpMethod.GET, Collections.emptyList(), null, @@ -142,7 +158,7 @@ void getRecipientDeliveryReport() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - RecipientDeliveryReport response = service.getForNumber("foo binary batch id", "foo number"); + RecipientDeliveryReport response = service.getForNumber(BATCH_ID, "+1234567890"); TestHelpers.recursiveEquals(response, recipientDeliveryReportMMSDto); } @@ -152,7 +168,7 @@ void listDefault() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/delivery_reports", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/delivery_reports", HttpMethod.GET, Collections.emptyList(), null, @@ -215,7 +231,7 @@ void list() throws ApiException { HttpRequest httpRequest0 = new HttpRequest( - "/xms/v1/foovalue/delivery_reports", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/delivery_reports", HttpMethod.GET, urlParameters0, null, @@ -225,7 +241,7 @@ void list() throws ApiException { Collections.singletonList(SMS_AUTH_NAMES)); HttpRequest httpRequest1 = new HttpRequest( - "/xms/v1/foovalue/delivery_reports", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/delivery_reports", HttpMethod.GET, urlParameters1, null, @@ -235,7 +251,7 @@ void list() throws ApiException { Collections.singletonList(SMS_AUTH_NAMES)); HttpRequest httpRequest2 = new HttpRequest( - "/xms/v1/foovalue/delivery_reports", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/delivery_reports", HttpMethod.GET, urlParameters2, null, diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java index 47087cf58..b9e810573 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/GroupsServiceTest.java @@ -20,6 +20,7 @@ import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.PaginationFillerHelper; import com.sinch.sdk.domains.sms.api.v1.GroupsService; @@ -46,6 +47,9 @@ class GroupsServiceTest extends BaseTest { static final String SMS_AUTH_NAMES = "BearerAuth"; + static final String SERVICE_PLAN_ID = "foo value"; + static final String GROUP_ID = "foo groupID"; + @GivenTextResource("/domains/sms/v1/groups/GroupDto.json") String jsonGroupDto; @@ -76,7 +80,11 @@ class GroupsServiceTest extends BaseTest { public void initMocks() { service = new GroupsServiceImpl( - httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); + httpClient, + serverConfiguration, + authManagers, + HttpMapper.getInstance(), + SERVICE_PLAN_ID); } @Test @@ -84,7 +92,10 @@ void get() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups/foo%20group%20ID", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/groups/" + + URLPathUtils.encodePathSegment(GROUP_ID), HttpMethod.GET, Collections.emptyList(), null, @@ -101,7 +112,7 @@ void get() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - Group response = service.get("foo group ID"); + Group response = service.get(GROUP_ID); TestHelpers.recursiveEquals(response, groupDto); } @@ -111,7 +122,7 @@ void create() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/groups", HttpMethod.POST, Collections.emptyList(), HttpMapper.getInstance() @@ -141,7 +152,7 @@ void listDefault() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/groups", HttpMethod.GET, Collections.emptyList(), null, @@ -177,7 +188,7 @@ void list() throws ApiException { HttpRequest httpRequest0 = new HttpRequest( - "/xms/v1/foovalue/groups", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/groups", HttpMethod.GET, urlParameters0, null, @@ -187,7 +198,7 @@ void list() throws ApiException { Collections.singletonList(SMS_AUTH_NAMES)); HttpRequest httpRequest1 = new HttpRequest( - "/xms/v1/foovalue/groups", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/groups", HttpMethod.GET, urlParameters1, null, @@ -197,7 +208,7 @@ void list() throws ApiException { Collections.singletonList(SMS_AUTH_NAMES)); HttpRequest httpRequest2 = new HttpRequest( - "/xms/v1/foovalue/groups", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/groups", HttpMethod.GET, urlParameters2, null, @@ -256,7 +267,10 @@ void replace() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups/group%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/groups/" + + URLPathUtils.encodePathSegment(GROUP_ID), HttpMethod.PUT, Collections.emptyList(), HttpMapper.getInstance() @@ -276,7 +290,7 @@ void replace() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - Group response = service.replace("group id", GroupRequest.builder().setName("foo").build()); + Group response = service.replace(GROUP_ID, GroupRequest.builder().setName("foo").build()); TestHelpers.recursiveEquals(response, groupDto); } @@ -286,7 +300,10 @@ void update() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups/group%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/groups/" + + URLPathUtils.encodePathSegment(GROUP_ID), HttpMethod.POST, Collections.emptyList(), HttpMapper.getInstance() @@ -306,7 +323,7 @@ void update() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - Group response = service.update("group id", GroupUpdateRequestDtoTest.requestDTO); + Group response = service.update(GROUP_ID, GroupUpdateRequestDtoTest.requestDTO); TestHelpers.recursiveEquals(response, groupDto); } @@ -316,7 +333,10 @@ void delete() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups/group%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/groups/" + + URLPathUtils.encodePathSegment(GROUP_ID), HttpMethod.DELETE, Collections.emptyList(), null, @@ -332,7 +352,7 @@ void delete() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - service.delete("group id"); + service.delete(GROUP_ID); } @Test @@ -340,7 +360,11 @@ void listMembers() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/groups/group%20id/members", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/groups/" + + URLPathUtils.encodePathSegment(GROUP_ID) + + "/members", HttpMethod.GET, Collections.emptyList(), null, @@ -358,7 +382,7 @@ void listMembers() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - Collection members = service.listMembers("group id"); + Collection members = service.listMembers(GROUP_ID); TestHelpers.recursiveEquals(members, new ArrayList<>(Arrays.asList("entry 1", "entry 2"))); } } diff --git a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java index 1a9d661f7..b6726d2f4 100644 --- a/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/sms/api/v1/adapters/InboundsServiceTest.java @@ -20,6 +20,7 @@ import com.sinch.sdk.core.http.HttpResponse; import com.sinch.sdk.core.http.URLParameter; import com.sinch.sdk.core.http.URLParameter.STYLE; +import com.sinch.sdk.core.http.URLPathUtils; import com.sinch.sdk.core.models.ServerConfiguration; import com.sinch.sdk.domains.PaginationFillerHelper; import com.sinch.sdk.domains.sms.api.v1.InboundsService; @@ -44,6 +45,8 @@ public class InboundsServiceTest extends BaseTest { static final String SMS_AUTH_NAMES = "BearerAuth"; + static final String SERVICE_PLAN_ID = "foo value"; + static final String BATCH_ID = "foo batchID"; @GivenTextResource("/domains/sms/v1/inbounds/InboundTextDto.json") String jsonTextMessageDto; @@ -76,7 +79,11 @@ public class InboundsServiceTest extends BaseTest { public void initMocks() { service = new InboundsServiceImpl( - httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), "foovalue"); + httpClient, + serverConfiguration, + authManagers, + HttpMapper.getInstance(), + SERVICE_PLAN_ID); } @Test @@ -84,7 +91,10 @@ void get() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/inbounds/foo%20binary%20batch%20id", + "/xms/v1/" + + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + + "/inbounds/" + + URLPathUtils.encodePathSegment(BATCH_ID), HttpMethod.GET, Collections.emptyList(), null, @@ -101,7 +111,7 @@ void get() throws ApiException { argThat(new HttpRequestMatcher(httpRequest)))) .thenReturn(httpResponse); - InboundMessage response = service.get("foo binary batch id"); + InboundMessage response = service.get(BATCH_ID); TestHelpers.recursiveEquals(response, textMessageDto); } @@ -111,7 +121,7 @@ void listDefault() throws ApiException { HttpRequest httpRequest = new HttpRequest( - "/xms/v1/foovalue/inbounds", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/inbounds", HttpMethod.GET, Collections.emptyList(), null, @@ -168,7 +178,7 @@ void list() throws ApiException { HttpRequest httpRequest0 = new HttpRequest( - "/xms/v1/foovalue/inbounds", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/inbounds", HttpMethod.GET, urlParameters0, null, @@ -178,7 +188,7 @@ void list() throws ApiException { Collections.singletonList(SMS_AUTH_NAMES)); HttpRequest httpRequest1 = new HttpRequest( - "/xms/v1/foovalue/inbounds", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/inbounds", HttpMethod.GET, urlParameters1, null, @@ -188,7 +198,7 @@ void list() throws ApiException { Collections.singletonList(SMS_AUTH_NAMES)); HttpRequest httpRequest2 = new HttpRequest( - "/xms/v1/foovalue/inbounds", + "/xms/v1/" + URLPathUtils.encodePathSegment(SERVICE_PLAN_ID) + "/inbounds", HttpMethod.GET, urlParameters2, null, From 8629f6073bef491290d832e0f5679825f7f0e705 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier <141755467+JPPortier@users.noreply.github.com> Date: Tue, 21 Jan 2025 10:15:52 +0100 Subject: [PATCH 57/65] DEVEXP-469: SMS's javadoc (#194) * doc (SMS): SMS's javadoc --- .../com/sinch/sdk/domains/sms/SMSService.java | 2 +- .../sdk/domains/sms/api/v1/SMSService.java | 37 ++++++++++++ .../domains/sms/api/v1/WebHooksService.java | 34 +++++++++++ .../sdk/domains/sms/api/v1/package-info.java | 6 ++ .../sms/models/v1/batches/package-info.java | 6 ++ .../v1/batches/request/BatchRequest.java | 8 +++ .../batches/request/UpdateBatchRequest.java | 6 ++ .../v1/batches/request/package-info.java | 6 ++ .../v1/batches/response/package-info.java | 6 ++ .../deliveryreports/BatchDeliveryReport.java | 9 +++ .../v1/deliveryreports/DeliveryReport.java | 6 ++ .../RecipientDeliveryReport.java | 10 ++++ .../v1/deliveryreports/package-info.java | 6 ++ .../deliveryreports/request/package-info.java | 6 ++ .../response/package-info.java | 6 ++ .../sms/models/v1/groups/package-info.java | 6 ++ .../v1/groups/request/package-info.java | 6 ++ .../v1/groups/response/package-info.java | 6 ++ .../models/v1/inbounds/InboundMessage.java | 9 +++ .../sms/models/v1/inbounds/package-info.java | 6 ++ .../v1/inbounds/request/package-info.java | 6 ++ .../v1/inbounds/response/package-info.java | 6 ++ .../domains/sms/models/v1/package-info.java | 6 ++ .../sms/models/v1/webhooks/SmsEvent.java | 7 ++- .../sms/models/v1/webhooks/package-info.java | 57 +++++++++++++++++++ .../src/main/com/sinch/sdk/package-info.java | 2 +- .../domains/sms/api/v1/BatchesService.java | 1 + .../sms/api/v1/DeliveryReportsService.java | 1 + .../sdk/domains/sms/api/v1/GroupsService.java | 1 + .../domains/sms/api/v1/InboundsService.java | 1 + pom.xml | 11 +++- 31 files changed, 280 insertions(+), 6 deletions(-) create mode 100644 client/src/main/com/sinch/sdk/domains/sms/api/v1/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/package-info.java create mode 100644 client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/package-info.java diff --git a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java index ca09e175c..4dccccb6e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/SMSService.java @@ -15,7 +15,7 @@ public interface SMSService { * @return V1 service instance for project * @see Documentation - * @since + * @since 1.5 */ com.sinch.sdk.domains.sms.api.v1.SMSService v1(); diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java index cec2c4e42..92f06fcce 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/SMSService.java @@ -1,14 +1,51 @@ package com.sinch.sdk.domains.sms.api.v1; +/** + * SMS Service + * + * @see https://developers.sinch.com/docs/sms/api-reference/ + * @since 1.5 + */ public interface SMSService { + /** + * Batches Service instance + * + * @return service instance for project + * @since 1.5 + */ BatchesService batches(); + /** + * Inbounds Service instance + * + * @return service instance for project + * @since 1.5 + */ InboundsService inbounds(); + /** + * Delivery Reports Service instance + * + * @return service instance for project + * @since 1.5 + */ DeliveryReportsService deliveryReports(); + /** + * Groups Service instance + * + * @return service instance for project + * @since 1.5 + */ GroupsService groups(); + /** + * WebHooksService Service instance + * + * @return service instance for project + * @since 1.5 + */ WebHooksService webhooks(); } diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java index 580cfadb6..1cf62c36c 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/WebHooksService.java @@ -4,6 +4,40 @@ import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; import java.util.Map; +/** + * SMS WebHooks service + * + *

Callbacks + * + *

A callback is an HTTP POST request with a notification made by the Sinch SMS REST API to a URI + * of your choosing. + * + *

The REST API expects the receiving server to respond with a response code within the 2xx + * success range. For 5xx the callback will be retried. For 429 + * the callback will be retried and the throughput will be lowered. For other status codes in the + * 4xx range the callback will not be retried. The first initial retry will happen 5 + * seconds after the first try. The next attempt is after 10 seconds, then after 20 seconds, after + * 40 seconds, after 80 seconds, doubling on every attempt. The last retry will be at 81920 seconds + * (or 22 hours 45 minutes) after the initial failed attempt. + * + *

The SMS REST API offers the following callback options which can be configured for your + * account upon request to your account manager. + * + *

    + *
  • Callback with mutual authentication over TLS (HTTPS) connection by provisioning the + * callback URL with client keystore and password. + *
  • Callback with basic authentication by provisioning the callback URL with username and + * password. + *
  • Callback with OAuth 2.0 by provisioning the callback URL with username, password and the + * URL to fetch OAuth access token. + *
  • Callback using AWS SNS by provisioning the callback URL with an Access Key ID, Secret Key + * and Region. + *
+ * + * @see https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/ + * @since 1.5 + */ public interface WebHooksService { SmsEvent parseEvent(String jsonPayload) throws ApiMappingException; diff --git a/client/src/main/com/sinch/sdk/domains/sms/api/v1/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/api/v1/package-info.java new file mode 100644 index 000000000..190f1b57f --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/api/v1/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS API interface + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.api.v1; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/package-info.java new file mode 100644 index 000000000..8527568af --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS Batches API related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.batches; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java index 15c37afe0..5af7766aa 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/BatchRequest.java @@ -1,3 +1,11 @@ package com.sinch.sdk.domains.sms.models.v1.batches.request; +/** + * Base class for all batch request classes + * + * @see com.sinch.sdk.domains.sms.api.v1.BatchesService#send(BatchRequest) + * @see com.sinch.sdk.domains.sms.api.v1.BatchesService#dryRun(BatchRequest) + * @see com.sinch.sdk.domains.sms.api.v1.BatchesService#replace(String, BatchRequest) + * @since 1.5 + */ public interface BatchRequest {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java index 80cd64316..781034cbe 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBatchRequest.java @@ -1,3 +1,9 @@ package com.sinch.sdk.domains.sms.models.v1.batches.request; +/** + * Base class for all classes supported to update batches + * + * @see com.sinch.sdk.domains.sms.api.v1.BatchesService#update(String, UpdateBatchRequest) + * @since 1.5 + */ public interface UpdateBatchRequest {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/package-info.java new file mode 100644 index 000000000..37e6560dc --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/package-info.java @@ -0,0 +1,6 @@ +/** + * Batches API requests related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.batches.request; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/package-info.java new file mode 100644 index 000000000..46deffe24 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/batches/response/package-info.java @@ -0,0 +1,6 @@ +/** + * Batches API responses related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.batches.response; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java index d474942eb..0bdf1319e 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/BatchDeliveryReport.java @@ -2,6 +2,15 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal.BatchDeliveryReportOneOfImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.BatchDeliveryReportQueryParameters; +/** + * Base class for all classes supporting Batch DeliveryReport + * + * @see com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService#get(String, + * BatchDeliveryReportQueryParameters) + * @see com.sinch.sdk.domains.sms.api.v1.WebHooksService#parseEvent(String) + * @since 1.5 + */ @JsonDeserialize(using = BatchDeliveryReportOneOfImpl.Deserializer.class) public interface BatchDeliveryReport extends DeliveryReport {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java index ab999d211..75d30610d 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/DeliveryReport.java @@ -2,4 +2,10 @@ import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +/** + * Base class for all classes supporting DeliveryReport + * + * @see com.sinch.sdk.domains.sms.api.v1.WebHooksService#parseEvent(String) + * @since 1.5 + */ public interface DeliveryReport extends SmsEvent {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java index 44d2265e3..536cb2204 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/RecipientDeliveryReport.java @@ -2,6 +2,16 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.internal.RecipientDeliveryReportOneOfImpl; +import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; +/** + * Base class for all classes supporting Recipient DeliveryReport + * + * @see com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService#getForNumber(String, String) + * @see + * com.sinch.sdk.domains.sms.api.v1.DeliveryReportsService#list(ListDeliveryReportsQueryParameters) + * @see com.sinch.sdk.domains.sms.api.v1.WebHooksService#parseEvent(String) + * @since 1.5 + */ @JsonDeserialize(using = RecipientDeliveryReportOneOfImpl.Deserializer.class) public interface RecipientDeliveryReport extends DeliveryReport {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/package-info.java new file mode 100644 index 000000000..00b4ce163 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS Delivery Reports API related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/package-info.java new file mode 100644 index 000000000..c6de71fda --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/request/package-info.java @@ -0,0 +1,6 @@ +/** + * Delivery Reports API requests related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.request; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/package-info.java new file mode 100644 index 000000000..a4facb36c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/response/package-info.java @@ -0,0 +1,6 @@ +/** + * Delivery Reports API responses related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.deliveryreports.response; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/package-info.java new file mode 100644 index 000000000..18ee160b4 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS Groups API related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.groups; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/package-info.java new file mode 100644 index 000000000..98b122470 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/request/package-info.java @@ -0,0 +1,6 @@ +/** + * Groups API requests related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.groups.request; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/package-info.java new file mode 100644 index 000000000..2ec79ea72 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/groups/response/package-info.java @@ -0,0 +1,6 @@ +/** + * Groups API responses related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.groups.response; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java index a689da166..a24878770 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/InboundMessage.java @@ -1,8 +1,17 @@ package com.sinch.sdk.domains.sms.models.v1.inbounds; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.internal.InboundInternalImpl; import com.sinch.sdk.domains.sms.models.v1.webhooks.SmsEvent; +/** + * Base class for all classes supporting InBounds + * + * @see com.sinch.sdk.domains.sms.api.v1.InboundsService#get(String) + * @see com.sinch.sdk.domains.sms.api.v1.InboundsService#list(ListInboundMessagesQueryParameters) + * @see com.sinch.sdk.domains.sms.api.v1.WebHooksService#parseEvent(String) + * @since 1.5 + */ @JsonDeserialize(using = InboundInternalImpl.Deserializer.class) public interface InboundMessage extends SmsEvent {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/package-info.java new file mode 100644 index 000000000..fcbc1eac7 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS Inbounds API related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.inbounds; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/package-info.java new file mode 100644 index 000000000..42b49db2e --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/request/package-info.java @@ -0,0 +1,6 @@ +/** + * Inbounds API requests related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.inbounds.request; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/package-info.java new file mode 100644 index 000000000..948cfcd60 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/response/package-info.java @@ -0,0 +1,6 @@ +/** + * Inbounds API responses related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.inbounds.response; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/package-info.java new file mode 100644 index 000000000..a31fb92a3 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/package-info.java @@ -0,0 +1,6 @@ +/** + * SMS API related models + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1; diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java index 48da3fbfc..6257897ec 100644 --- a/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/SmsEvent.java @@ -3,6 +3,11 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.domains.sms.models.v1.webhooks.internal.WebhookEventOneOfImpl; -/** Interface defining a WebHook event */ +/** + * Base class for all WebHook event's class + * + * @see com.sinch.sdk.domains.sms.api.v1.WebHooksService#parseEvent(String) + * @since 1.5 + */ @JsonDeserialize(using = WebhookEventOneOfImpl.Deserializer.class) public interface SmsEvent {} diff --git a/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/package-info.java b/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/package-info.java new file mode 100644 index 000000000..f1aa66b4d --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/sms/models/v1/webhooks/package-info.java @@ -0,0 +1,57 @@ +/** + * SMS API webhooks related models + * + *

Incoming SMS WebHook

+ * + *

An inbound message is a message sent to one of your short codes or long numbers from a mobile + * phone. To receive inbound message callbacks, a URL needs to be added to your REST API. + * + *

This URL can be specified in your Dashboard. + * + *

See https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/operation/incomingSMS + * + *

Delivery Report WebHook

+ * + *

A delivery report contains the status and status code for each recipient of a batch. To get a + * delivery report callback for a message or batch of messages, set the delivery_report + * field accordingly when creating a batch. + * + *

The following is provided so you can better understand our webhooks/callbacks. Configuration + * of both webhooks and the type of delivery report requested happens when sending a batch. + * + *

Callback URL + * + *

The callback URL can either be provided for each batch or provisioned globally for your + * account in your Sinch Customer Dashboard. + * Learn how to configure a webhook/callback here + * + *

Type + * + *

The type is the type of delivery report webhook. The response will vary depending + * on the webhook delivery report you selected when the batch was sent, so choose the appropriate + * selection under "One of". + * + *

    + *
  • The delivery_report_sms and delivery_report_mms types are + * documented under Delivery report. + *

    These are reports containing either + * a full report or summary report, depending on your selection at the time the batch was + * sent. + *

  • The recipient_delivery_report_sms and recipient_delivery_report_mms + * delivery report types are documented under Recipient delivery report. + *

    These are delivery reports for recipient phone numbers. If you set per_recipient + * for the delivery_report parameter when sending the batch, a recipient + * report gets sent to you for each status change for each recipient in your batch. If you set + * per_recipient_final, a recipient report gets sent to you for the final status + * of each recipient in your batch. + *

+ * + * See https://developers.sinch.com/docs/sms/api-reference/sms/tag/Webhooks/#tag/Webhooks/operation/deliveryReport + * + * @since 1.5 + */ +package com.sinch.sdk.domains.sms.models.v1.webhooks; diff --git a/client/src/main/com/sinch/sdk/package-info.java b/client/src/main/com/sinch/sdk/package-info.java index d930893d6..2e4779f4f 100644 --- a/client/src/main/com/sinch/sdk/package-info.java +++ b/client/src/main/com/sinch/sdk/package-info.java @@ -1,5 +1,5 @@ /** - * Sinch Java SDK for Numbers, SMS & Verification + * Sinch Java SDK for Conversation, Numbers, SMS, Verification & Voice * *

Provides the client necessary to interface with Sinch APIS * diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java index 79feeba53..1b979d7e0 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/BatchesService.java @@ -20,6 +20,7 @@ import com.sinch.sdk.domains.sms.models.v1.batches.response.DryRunResponse; import com.sinch.sdk.domains.sms.models.v1.batches.response.ListBatchesResponse; +/** Batches Service */ public interface BatchesService { /** diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java index 65e6bc91b..363b85efb 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/DeliveryReportsService.java @@ -17,6 +17,7 @@ import com.sinch.sdk.domains.sms.models.v1.deliveryreports.request.ListDeliveryReportsQueryParameters; import com.sinch.sdk.domains.sms.models.v1.deliveryreports.response.ListDeliveryReportsResponse; +/** Delivery reports Service */ public interface DeliveryReportsService { /** diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java index 2aaf83813..f40560e1e 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/GroupsService.java @@ -18,6 +18,7 @@ import com.sinch.sdk.domains.sms.models.v1.groups.response.ListGroupsResponse; import java.util.List; +/** Groups Service */ public interface GroupsService { /** diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java index 9ffbde1dd..d53c5d1e9 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/api/v1/InboundsService.java @@ -15,6 +15,7 @@ import com.sinch.sdk.domains.sms.models.v1.inbounds.request.ListInboundMessagesQueryParameters; import com.sinch.sdk.domains.sms.models.v1.inbounds.response.ListInboundsResponse; +/** Inbounds Service */ public interface InboundsService { /** diff --git a/pom.xml b/pom.xml index d50d1e596..267ebdc2e 100644 --- a/pom.xml +++ b/pom.xml @@ -126,6 +126,8 @@ com.sinch.sdk.auth*; com.sinch.sdk.core.http; com.sinch.sdk.core.http.*; + com.sinch.sdk.core.databind; + com.sinch.sdk.core.databind.*; com.sinch.sdk.core.utils.databind; com.sinch.sdk.http; com.sinch.sdk.pagination.Page*; @@ -193,7 +195,7 @@ Sinch Client - com.sinch.sdk* + com.sinch.sdk:com.sinch.sdk.models Core package @@ -207,19 +209,22 @@ Numbers com.sinch.sdk.domains.numbers* + SMS - com.sinch.sdk.domains.sms* + com.sinch.sdk.domains.sms.models.v1*:com.sinch.sdk.domains.sms.api.v1* Verification - com.sinch.sdk.domains.verification.models.v1*:com.sinch.sdk.domains.verification.api.v1* + com.sinch.sdk.domains.verification:com.sinch.sdk.domains.verification.models.v1*:com.sinch.sdk.domains.verification.api.v1* Voice com.sinch.sdk.domains.voice* + + From 42ca372e325ca3bbac328ec25fac4887fa6938ac Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 22 Jan 2025 10:30:30 +0100 Subject: [PATCH 58/65] feat (Conversation): Synch with latest generated sources --- .../conversation/api/v1/internal/AppApi.java | 1 + .../conversation/api/v1/internal/ContactApi.java | 6 ++++++ .../api/v1/internal/ConversationApi.java | 13 +++++++++++++ .../conversation/api/v1/internal/EventsApi.java | 4 ++++ .../conversation/api/v1/internal/MessagesApi.java | 15 +++++++++++++++ .../conversation/api/v1/internal/WebhooksApi.java | 1 + .../request/QueryCapabilityRequest.java | 2 +- .../response/QueryCapabilityResponse.java | 2 +- .../contact/request/GetChannelProfileRequest.java | 2 +- .../v1/events/request/SendEventRequest.java | 4 +++- .../v1/messages/request/SendMessageRequest.java | 4 +++- .../internal/CreateWebhookRequestInternal.java | 10 ---------- 12 files changed, 49 insertions(+), 15 deletions(-) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/AppApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/AppApi.java index 87bdb3b32..20e980aa5 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/AppApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/AppApi.java @@ -427,6 +427,7 @@ private HttpRequest appUpdateAppRequestBuilder( .replaceAll("\\{" + "app_id" + "\\}", URLPathUtils.encodePathSegment(appId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != updateMask) { localVarQueryParams.add( new URLParameter( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ContactApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ContactApi.java index 8daf06e90..70753721e 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ContactApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ContactApi.java @@ -483,26 +483,31 @@ private HttpRequest contactListContactsRequestBuilder( "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != pageSize) { localVarQueryParams.add( new URLParameter( "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageToken) { localVarQueryParams.add( new URLParameter( "page_token", pageToken, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != externalId) { localVarQueryParams.add( new URLParameter( "external_id", externalId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != channel) { localVarQueryParams.add( new URLParameter( "channel", channel, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != identity) { localVarQueryParams.add( new URLParameter( @@ -708,6 +713,7 @@ private HttpRequest contactUpdateContactRequestBuilder( "\\{" + "contact_id" + "\\}", URLPathUtils.encodePathSegment(contactId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != updateMask) { localVarQueryParams.add( new URLParameter( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java index e817c65f3..dd39f4f8e 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/ConversationApi.java @@ -515,31 +515,37 @@ private HttpRequest conversationListConversationsRequestBuilder( "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != appId) { localVarQueryParams.add( new URLParameter( "app_id", appId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != contactId) { localVarQueryParams.add( new URLParameter( "contact_id", contactId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != onlyActive) { localVarQueryParams.add( new URLParameter( "only_active", onlyActive, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageSize) { localVarQueryParams.add( new URLParameter( "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageToken) { localVarQueryParams.add( new URLParameter( "page_token", pageToken, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != activeChannel) { localVarQueryParams.add( new URLParameter( @@ -668,26 +674,31 @@ private HttpRequest conversationListRecentConversationsRequestBuilder( "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != appId) { localVarQueryParams.add( new URLParameter( "app_id", appId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != onlyActive) { localVarQueryParams.add( new URLParameter( "only_active", onlyActive, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageSize) { localVarQueryParams.add( new URLParameter( "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageToken) { localVarQueryParams.add( new URLParameter( "page_token", pageToken, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != order) { localVarQueryParams.add( new URLParameter("order", order, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); @@ -899,11 +910,13 @@ private HttpRequest conversationUpdateConversationRequestBuilder( URLPathUtils.encodePathSegment(conversationId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != updateMask) { localVarQueryParams.add( new URLParameter( "update_mask", updateMask, URLParameter.STYLE.valueOf("form".toUpperCase()), false)); } + if (null != metadataUpdateStrategy) { localVarQueryParams.add( new URLParameter( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/EventsApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/EventsApi.java index bfffc668e..b8e16e461 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/EventsApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/EventsApi.java @@ -275,6 +275,7 @@ private HttpRequest eventsListEventsRequestBuilder( "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != conversationId) { localVarQueryParams.add( new URLParameter( @@ -283,16 +284,19 @@ private HttpRequest eventsListEventsRequestBuilder( URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != contactId) { localVarQueryParams.add( new URLParameter( "contact_id", contactId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageSize) { localVarQueryParams.add( new URLParameter( "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageToken) { localVarQueryParams.add( new URLParameter( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/MessagesApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/MessagesApi.java index 538ff4beb..ed79a3bda 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/MessagesApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/MessagesApi.java @@ -125,6 +125,7 @@ private HttpRequest messagesDeleteMessageRequestBuilder( "\\{" + "message_id" + "\\}", URLPathUtils.encodePathSegment(messageId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != messagesSource) { localVarQueryParams.add( new URLParameter( @@ -223,6 +224,7 @@ private HttpRequest messagesGetMessageRequestBuilder( "\\{" + "message_id" + "\\}", URLPathUtils.encodePathSegment(messageId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != messagesSource) { localVarQueryParams.add( new URLParameter( @@ -410,6 +412,7 @@ private HttpRequest messagesListMessagesRequestBuilder( "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != conversationId) { localVarQueryParams.add( new URLParameter( @@ -418,16 +421,19 @@ private HttpRequest messagesListMessagesRequestBuilder( URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != contactId) { localVarQueryParams.add( new URLParameter( "contact_id", contactId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != appId) { localVarQueryParams.add( new URLParameter( "app_id", appId, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != channelIdentity) { localVarQueryParams.add( new URLParameter( @@ -436,30 +442,36 @@ private HttpRequest messagesListMessagesRequestBuilder( URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != startTime) { localVarQueryParams.add( new URLParameter( "start_time", startTime, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != endTime) { localVarQueryParams.add( new URLParameter( "end_time", endTime, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageSize) { localVarQueryParams.add( new URLParameter( "page_size", pageSize, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != pageToken) { localVarQueryParams.add( new URLParameter( "page_token", pageToken, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != view) { localVarQueryParams.add( new URLParameter("view", view, URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != messagesSource) { localVarQueryParams.add( new URLParameter( @@ -468,6 +480,7 @@ private HttpRequest messagesListMessagesRequestBuilder( URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != onlyRecipientOriginated) { localVarQueryParams.add( new URLParameter( @@ -476,6 +489,7 @@ private HttpRequest messagesListMessagesRequestBuilder( URLParameter.STYLE.valueOf("form".toUpperCase()), true)); } + if (null != channel) { localVarQueryParams.add( new URLParameter( @@ -680,6 +694,7 @@ private HttpRequest messagesUpdateMessageMetadataRequestBuilder( "\\{" + "message_id" + "\\}", URLPathUtils.encodePathSegment(messageId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != messagesSource) { localVarQueryParams.add( new URLParameter( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/WebhooksApi.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/WebhooksApi.java index 2409a57ff..7072d87b9 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/WebhooksApi.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/api/v1/internal/WebhooksApi.java @@ -449,6 +449,7 @@ private HttpRequest webhooksUpdateWebhookRequestBuilder( "\\{" + "webhook_id" + "\\}", URLPathUtils.encodePathSegment(webhookId.toString())); List localVarQueryParams = new ArrayList<>(); + if (null != updateMask) { localVarQueryParams.add( new URLParameter( diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/request/QueryCapabilityRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/request/QueryCapabilityRequest.java index e24c3ac6e..52401c7d7 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/request/QueryCapabilityRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/request/QueryCapabilityRequest.java @@ -25,7 +25,7 @@ public interface QueryCapabilityRequest { String getAppId(); /** - * Get recipient + * Identifies the recipient. * * @return recipient */ diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/response/QueryCapabilityResponse.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/response/QueryCapabilityResponse.java index b8934c16c..7866542f6 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/response/QueryCapabilityResponse.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/capability/response/QueryCapabilityResponse.java @@ -28,7 +28,7 @@ public interface QueryCapabilityResponse { String getAppId(); /** - * Get recipient + * Identifies the recipient. * * @return recipient */ diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/contact/request/GetChannelProfileRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/contact/request/GetChannelProfileRequest.java index 67173b22b..cb2765809 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/contact/request/GetChannelProfileRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/contact/request/GetChannelProfileRequest.java @@ -25,7 +25,7 @@ public interface GetChannelProfileRequest { String getAppId(); /** - * Get recipient + * Identifies the recipient. * * @return recipient */ diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/request/SendEventRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/request/SendEventRequest.java index 7bd59335c..76b53c41c 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/request/SendEventRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/events/request/SendEventRequest.java @@ -67,7 +67,9 @@ public interface SendEventRequest { MessageQueue getQueue(); /** - * Get recipient + * Identifies the recipient. If Dispatch Mode is + * used, you must use the identified_by field. * * @return recipient */ diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java index 842f04343..a56b19b40 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/request/SendMessageRequest.java @@ -109,7 +109,9 @@ public interface SendMessageRequest { MessageQueue getQueue(); /** - * Get recipient + * Identifies the recipient. If Dispatch Mode is + * used, you must use the identified_by field. * * @return recipient */ diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/webhooks/internal/CreateWebhookRequestInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/webhooks/internal/CreateWebhookRequestInternal.java index eeac1e3b5..310932923 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/webhooks/internal/CreateWebhookRequestInternal.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/webhooks/internal/CreateWebhookRequestInternal.java @@ -105,16 +105,6 @@ interface Builder { */ Builder setClientCredentials(ClientCredentials clientCredentials); - /** - * see getter - * - * @param id see getter - * @return Current builder - * @see #getId - * @readOnly This field is returned by the server and cannot be modified - */ - Builder setId(String id); - /** * see getter * From d2b5573bd0ae3502382b0472025a05f44b54541c Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 22 Jan 2025 10:49:05 +0100 Subject: [PATCH 59/65] fix (Conversation): Internal 'ChannelSpecificMessageInternal' no longer reference 'ChannelSpecificMessage' --- .../internal/AppMessageInternalMapper.java | 11 +++ .../ChannelSpecificMessageInternalMapper.java | 90 ++++++++++++++++++- .../ChannelSpecificMessageInternal.java | 5 +- .../ChannelSpecificMessageInternalImpl.java | 14 +-- .../ChannelSpecificMessageDtoTest.java | 26 ++++++ .../ChannelSpecificMessageFlowsDto.json | 30 +++++++ 6 files changed, 163 insertions(+), 13 deletions(-) create mode 100644 openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/types/channelspecific/ChannelSpecificMessageDtoTest.java create mode 100644 openapi-contracts/src/test/resources/domains/conversation/v1/messages/types/channelspecific/ChannelSpecificMessageFlowsDto.json diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/AppMessageInternalMapper.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/AppMessageInternalMapper.java index cd439f287..477c72508 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/AppMessageInternalMapper.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/AppMessageInternalMapper.java @@ -4,10 +4,12 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; import com.sinch.sdk.domains.conversation.models.v1.messages.types.card.CardMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.card.CardMessageImpl; import com.sinch.sdk.domains.conversation.models.v1.messages.types.carousel.CarouselMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.carousel.CarouselMessageMapper; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific.ChannelSpecificMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.choice.ChoiceMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.choice.ChoiceMessageImpl; import com.sinch.sdk.domains.conversation.models.v1.messages.types.contactinfo.ContactInfoMessage; @@ -22,6 +24,7 @@ import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessageMapper; import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessageImpl; +import java.util.Map; public class AppMessageInternalMapper { @@ -87,6 +90,14 @@ public OptionalValue templateMessage() { public OptionalValue textMessage() { return super.textMessage(); } + + @Override + @JsonSerialize( + using = ChannelSpecificMessageInternalMapper.ChannelSpecificMessageMapSerializer.class) + public OptionalValue> + channelSpecificMessage() { + return super.channelSpecificMessage(); + } } static class AppMessageInternalBuilderMapperMixin extends AppMessageInternalImpl.Builder { diff --git a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalMapper.java b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalMapper.java index 13a3904a0..27173859d 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalMapper.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalMapper.java @@ -1,18 +1,32 @@ package com.sinch.sdk.domains.conversation.models.v1.messages.internal; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.SerializerProvider; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.module.SimpleModule; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.sinch.sdk.core.models.OptionalValue; import com.sinch.sdk.core.utils.databind.Mapper; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.messages.internal.ChannelSpecificMessageInternal.MessageTypeEnum; import com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific.ChannelSpecificMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific.whatsapp.flows.FlowChannelSpecificMessage; import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; public class ChannelSpecificMessageInternalMapper { + private static final Logger LOGGER = + Logger.getLogger(ChannelSpecificMessageInternalMapper.class.getName()); public static void initMapper() { SimpleModule module = new SimpleModule().addDeserializer(ChannelSpecificMessage.class, new Deserializer()); + Mapper.getInstance().registerModule(module); } @@ -30,10 +44,80 @@ public Deserializer(Class vc) { public ChannelSpecificMessage deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - ChannelSpecificMessageMessageInternalImpl deserialized = + Object deserialized = jp.readValueAs(ChannelSpecificMessageInternal.class); + + if (null == deserialized) { + return null; + } + if (!(deserialized instanceof ChannelSpecificMessageInternal)) { + // do not throw exception to not break all schema's deserialization + LOGGER.log(Level.SEVERE, "Input data does not match schema: {}", deserialized); + return null; + } + + ChannelSpecificMessageInternalImpl channelSpecificMessageInternalImpl = + (ChannelSpecificMessageInternalImpl) deserialized; + ChannelSpecificMessageMessageInternalImpl channelSpecificMessageMessageInternal = (ChannelSpecificMessageMessageInternalImpl) - jp.readValueAs(ChannelSpecificMessageMessageInternal.class); - return (ChannelSpecificMessage) deserialized.getActualInstance(); + channelSpecificMessageInternalImpl.getMessage(); + + if (null == channelSpecificMessageMessageInternal) { + return null; + } + return (ChannelSpecificMessage) channelSpecificMessageMessageInternal.getActualInstance(); + } + } + + static class ChannelSpecificMessageMapSerializer + extends StdSerializer>> { + + public ChannelSpecificMessageMapSerializer() { + this(null); + } + + public ChannelSpecificMessageMapSerializer( + Class>> t) { + super(t); + } + + @Override + public void serialize( + OptionalValue> raw, + JsonGenerator jgen, + SerializerProvider provider) + throws IOException { + + if (null == raw || !raw.isPresent()) { + return; + } + + Map value = raw.get(); + if (null == value) { + jgen.writeObject(null); + return; + } + + Map out = new HashMap<>(value.size()); + value.forEach( + (channel, message) -> { + ChannelSpecificMessageMessageInternalImpl internal = + new ChannelSpecificMessageMessageInternalImpl(); + internal.setActualInstance(message); + + MessageTypeEnum type = null; + ChannelSpecificMessageInternal.Builder builder = + ChannelSpecificMessageInternal.builder(); + if (message instanceof FlowChannelSpecificMessage) { + type = MessageTypeEnum.FLOWS; + } else { + // do not throw exception to not break all schema's serialization + LOGGER.log(Level.SEVERE, "Unexpected message: {}", message); + } + builder.setMessageType(type).setMessage(internal); + out.put(channel, builder.build()); + }); + + jgen.writeObject(out); } } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternal.java index 7a90796dc..5bb8819ab 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternal.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternal.java @@ -13,7 +13,6 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.sinch.sdk.core.utils.EnumDynamic; import com.sinch.sdk.core.utils.EnumSupportDynamic; -import com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific.ChannelSpecificMessage; import java.util.Arrays; import java.util.stream.Stream; @@ -57,7 +56,7 @@ public static String valueOf(MessageTypeEnum e) { * * @return message */ - ChannelSpecificMessage getMessage(); + ChannelSpecificMessageMessageInternal getMessage(); /** * Getting builder @@ -87,7 +86,7 @@ interface Builder { * @return Current builder * @see #getMessage */ - Builder setMessage(ChannelSpecificMessage message); + Builder setMessage(ChannelSpecificMessageMessageInternal message); /** * Create instance diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalImpl.java index 42e87c7c7..e835b115e 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalImpl.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/models/v1/messages/internal/ChannelSpecificMessageInternalImpl.java @@ -7,7 +7,6 @@ import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.sinch.sdk.core.models.OptionalValue; -import com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific.ChannelSpecificMessage; import java.util.Objects; @JsonPropertyOrder({ @@ -25,12 +24,13 @@ public class ChannelSpecificMessageInternalImpl implements ChannelSpecificMessag public static final String JSON_PROPERTY_MESSAGE = "message"; - private OptionalValue message; + private OptionalValue message; public ChannelSpecificMessageInternalImpl() {} protected ChannelSpecificMessageInternalImpl( - OptionalValue messageType, OptionalValue message) { + OptionalValue messageType, + OptionalValue message) { this.messageType = messageType; this.message = message; } @@ -47,13 +47,13 @@ public OptionalValue messageType() { } @JsonIgnore - public ChannelSpecificMessage getMessage() { + public ChannelSpecificMessageMessageInternal getMessage() { return message.orElse(null); } @JsonProperty(JSON_PROPERTY_MESSAGE) @JsonInclude(value = JsonInclude.Include.ALWAYS) - public OptionalValue message() { + public OptionalValue message() { return message; } @@ -100,7 +100,7 @@ private String toIndentedString(Object o) { @JsonPOJOBuilder(withPrefix = "set") static class Builder implements ChannelSpecificMessageInternal.Builder { OptionalValue messageType = OptionalValue.empty(); - OptionalValue message = OptionalValue.empty(); + OptionalValue message = OptionalValue.empty(); @JsonProperty(JSON_PROPERTY_MESSAGE_TYPE) public Builder setMessageType(MessageTypeEnum messageType) { @@ -109,7 +109,7 @@ public Builder setMessageType(MessageTypeEnum messageType) { } @JsonProperty(JSON_PROPERTY_MESSAGE) - public Builder setMessage(ChannelSpecificMessage message) { + public Builder setMessage(ChannelSpecificMessageMessageInternal message) { this.message = OptionalValue.of(message); return this; } diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/types/channelspecific/ChannelSpecificMessageDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/types/channelspecific/ChannelSpecificMessageDtoTest.java new file mode 100644 index 000000000..af671bec3 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/messages/types/channelspecific/ChannelSpecificMessageDtoTest.java @@ -0,0 +1,26 @@ +package com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific; + +import com.adelean.inject.resources.junit.jupiter.GivenTextResource; +import com.adelean.inject.resources.junit.jupiter.TestWithResources; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.sinch.sdk.core.TestHelpers; +import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationBaseTest; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.channelspecific.whatsapp.flows.FlowChannelSpecificMessageDtoTest; +import org.junit.jupiter.api.Test; + +@TestWithResources +public class ChannelSpecificMessageDtoTest extends ConversationBaseTest { + + @GivenTextResource( + "/domains/conversation/v1/messages/types/channelspecific/ChannelSpecificMessageFlowsDto.json") + static String jsonChannelSpecificMessageFlowsDto; + + @Test + void deserializeChannelSpecificMessageFlowsDto() throws JsonProcessingException { + Object deserialized = + objectMapper.readValue(jsonChannelSpecificMessageFlowsDto, ChannelSpecificMessage.class); + + TestHelpers.recursiveEquals( + deserialized, FlowChannelSpecificMessageDtoTest.flowChannelSpecificMessageHeaderDocument); + } +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/types/channelspecific/ChannelSpecificMessageFlowsDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/types/channelspecific/ChannelSpecificMessageFlowsDto.json new file mode 100644 index 000000000..000eedbdd --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/types/channelspecific/ChannelSpecificMessageFlowsDto.json @@ -0,0 +1,30 @@ +{ + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "document", + "document": { + "link": "a document URL link" + } + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } + } + } +} From 329a2182c241d168f9d91cb89834396f59cac254 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 22 Jan 2025 11:06:02 +0100 Subject: [PATCH 60/65] test (Conversation/Test): Fix unit test payloads for 'channel_specific_message' --- .../message/MessageSubmitEventDtoTest.java | 4 +- .../request/InjectAppMessageRequestDto.json | 46 +++++++++--------- .../v1/messages/AppMessageCardDto.json | 45 +++++++++--------- .../v1/messages/AppMessageCarouselDto.json | 45 +++++++++--------- .../v1/messages/AppMessageChoiceDto.json | 45 +++++++++--------- .../v1/messages/AppMessageContactInfoDto.json | 45 +++++++++--------- .../v1/messages/AppMessageListDto.json | 45 +++++++++--------- .../v1/messages/AppMessageLocationDto.json | 47 ++++++++++--------- .../v1/messages/AppMessageMediaDto.json | 45 +++++++++--------- .../v1/messages/AppMessageTemplateDto.json | 45 +++++++++--------- .../v1/messages/AppMessageTextDto.json | 45 +++++++++--------- .../ConversationMessageAppTextRequestDto.json | 45 +++++++++--------- ...ConversationMessageAppTextResponseDto.json | 45 +++++++++--------- .../request/SendCardMessageRequestDto.json | 45 +++++++++--------- .../SendCarouselMessageRequestDto.json | 45 +++++++++--------- .../request/SendChoiceMessageRequestDto.json | 45 +++++++++--------- .../SendContactInfoMessageRequestDto.json | 45 +++++++++--------- .../request/SendListMessageRequestDto.json | 45 +++++++++--------- .../SendLocationMessageRequestDto.json | 45 +++++++++--------- .../request/SendMediaMessageRequestDto.json | 45 +++++++++--------- .../SendTemplateMessageRequestDto.json | 45 +++++++++--------- .../request/SendTextMessageRequestDto.json | 45 +++++++++--------- .../request/TranscodeMessageRequestDto.json | 45 +++++++++--------- .../events/message/MessageSubmitEventDto.json | 45 +++++++++--------- 24 files changed, 555 insertions(+), 487 deletions(-) diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/message/MessageSubmitEventDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/message/MessageSubmitEventDtoTest.java index 9c7c83051..40c1f004e 100644 --- a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/message/MessageSubmitEventDtoTest.java +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/v1/webhooks/events/message/MessageSubmitEventDtoTest.java @@ -21,7 +21,7 @@ public class MessageSubmitEventDtoTest extends ConversationBaseTest { MessageSubmitEvent messageSubmitEventDto; @GivenTextResource("domains/conversation/v1/webhooks/events/message/MessageSubmitEventDto.json") - String jsonMessageInboundEventDto; + String jsonMessageSubmitEventDto; public static MessageSubmitEvent expectedMessageInboundEvent = MessageSubmitEvent.builder() @@ -46,7 +46,7 @@ public class MessageSubmitEventDtoTest extends ConversationBaseTest { @Test void serialize() throws JsonProcessingException, JSONException { String serializedString = objectMapper.writeValueAsString(expectedMessageInboundEvent); - JSONAssert.assertEquals(jsonMessageInboundEventDto, serializedString, true); + JSONAssert.assertEquals(jsonMessageSubmitEventDto, serializedString, true); } @Test diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectAppMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectAppMessageRequestDto.json index 458a4affc..7260c95eb 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectAppMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/conversations/request/InjectAppMessageRequestDto.json @@ -50,27 +50,30 @@ }, "channel_specific_message": { "MESSENGER": { - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_id": "1", - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_cta": "Book!", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_price": 100, - "product_description": "description", - "product_name": "name" + "message_type": "FLOWS", + "message": { + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_id": "1", + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_cta": "Book!", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_price": 100, + "product_description": "description", + "product_name": "name" + } } } } @@ -94,4 +97,3 @@ "processing_mode": "CONVERSATION", "metadata": "metdata value" } -} \ No newline at end of file diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCardDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCardDto.json index d4723cabb..85b484940 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCardDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCardDto.json @@ -87,27 +87,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCarouselDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCarouselDto.json index ca93bbd54..66a0da940 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCarouselDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageCarouselDto.json @@ -125,27 +125,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageChoiceDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageChoiceDto.json index e3243c3c8..e7475d334 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageChoiceDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageChoiceDto.json @@ -85,27 +85,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageContactInfoDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageContactInfoDto.json index d3fc0f62f..f0ccf7004 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageContactInfoDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageContactInfoDto.json @@ -90,27 +90,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageListDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageListDto.json index 4b021c13f..4f6cf1382 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageListDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageListDto.json @@ -76,27 +76,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageLocationDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageLocationDto.json index ec26b3ce3..fa541d285 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageLocationDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageLocationDto.json @@ -54,27 +54,30 @@ }, "channel_specific_message": { "MESSENGER": { - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_id": "1", - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_cta": "Book!", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_price": 100, - "product_description": "description", - "product_name": "name" + "message_type": "FLOWS", + "message": { + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_id": "1", + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_cta": "Book!", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_price": 100, + "product_description": "description", + "product_name": "name" + } } } } @@ -84,4 +87,4 @@ "type": "BOT", "picture_url": "picture_url value" } -} \ No newline at end of file +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageMediaDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageMediaDto.json index 0dee3bf31..0e05cf111 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageMediaDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageMediaDto.json @@ -52,27 +52,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTemplateDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTemplateDto.json index 36955f068..2794e5d54 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTemplateDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTemplateDto.json @@ -64,27 +64,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTextDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTextDto.json index 4ac288588..41dc6bbc7 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTextDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/AppMessageTextDto.json @@ -49,27 +49,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextRequestDto.json index ab38eebdf..34ed421ad 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextRequestDto.json @@ -62,27 +62,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextResponseDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextResponseDto.json index 315d05ef4..f84fb9514 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextResponseDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/ConversationMessageAppTextResponseDto.json @@ -64,27 +64,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCardMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCardMessageRequestDto.json index afa49059c..595c3eef9 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCardMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCardMessageRequestDto.json @@ -92,27 +92,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCarouselMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCarouselMessageRequestDto.json index 722255ac5..51be6daa9 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCarouselMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendCarouselMessageRequestDto.json @@ -129,27 +129,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendChoiceMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendChoiceMessageRequestDto.json index 1d6ce54ed..d91178214 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendChoiceMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendChoiceMessageRequestDto.json @@ -89,27 +89,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendContactInfoMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendContactInfoMessageRequestDto.json index b766c0997..21b42ab85 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendContactInfoMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendContactInfoMessageRequestDto.json @@ -94,27 +94,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendListMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendListMessageRequestDto.json index 460085b75..4e75019f3 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendListMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendListMessageRequestDto.json @@ -80,27 +80,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendLocationMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendLocationMessageRequestDto.json index 37f91e641..e41a8f0fd 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendLocationMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendLocationMessageRequestDto.json @@ -59,27 +59,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendMediaMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendMediaMessageRequestDto.json index d6aa6657a..97ef388a2 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendMediaMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendMediaMessageRequestDto.json @@ -57,27 +57,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTemplateMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTemplateMessageRequestDto.json index 600d66b5f..c7c2608c9 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTemplateMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTemplateMessageRequestDto.json @@ -68,27 +68,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTextMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTextMessageRequestDto.json index 26a388522..717e96c4a 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTextMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/messages/request/SendTextMessageRequestDto.json @@ -54,27 +54,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/transcoding/request/TranscodeMessageRequestDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/transcoding/request/TranscodeMessageRequestDto.json index 6bc7bda84..ea422df4c 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/transcoding/request/TranscodeMessageRequestDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/transcoding/request/TranscodeMessageRequestDto.json @@ -56,27 +56,30 @@ }, "channel_specific_message": { "MESSENGER": { - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_id": "1", - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_cta": "Book!", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_price": 100, - "product_description": "description", - "product_name": "name" + "message_type": "FLOWS", + "message": { + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_id": "1", + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_cta": "Book!", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_price": 100, + "product_description": "description", + "product_name": "name" + } } } } diff --git a/openapi-contracts/src/test/resources/domains/conversation/v1/webhooks/events/message/MessageSubmitEventDto.json b/openapi-contracts/src/test/resources/domains/conversation/v1/webhooks/events/message/MessageSubmitEventDto.json index c1f6071ae..142f090c6 100644 --- a/openapi-contracts/src/test/resources/domains/conversation/v1/webhooks/events/message/MessageSubmitEventDto.json +++ b/openapi-contracts/src/test/resources/domains/conversation/v1/webhooks/events/message/MessageSubmitEventDto.json @@ -65,27 +65,30 @@ }, "channel_specific_message": { "MESSENGER": { - "flow_id": "1", - "flow_cta": "Book!", - "header": { - "type": "text", - "text": "text header value" - }, - "body": { - "text": "Flow message body" - }, - "footer": { - "text": "Flow message footer" - }, - "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", - "flow_mode": "draft", - "flow_action": "navigate", - "flow_action_payload": { - "screen": "", - "data": { - "product_name": "name", - "product_description": "description", - "product_price": 100 + "message_type": "FLOWS", + "message": { + "flow_id": "1", + "flow_cta": "Book!", + "header": { + "type": "text", + "text": "text header value" + }, + "body": { + "text": "Flow message body" + }, + "footer": { + "text": "Flow message footer" + }, + "flow_token": "AQAAAAACS5FpgQ_cAAAAAD0QI3s.", + "flow_mode": "draft", + "flow_action": "navigate", + "flow_action_payload": { + "screen": "", + "data": { + "product_name": "name", + "product_description": "description", + "product_price": 100 + } } } } From a8f57819ea774b5c1fe803b6e13b5c5793019df2 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 23 Jan 2025 19:46:50 +0100 Subject: [PATCH 61/65] doc (SMS): Synch with latest SMS OAS file --- .../sms/models/v1/batches/request/UpdateBinaryRequest.java | 5 ++++- .../domains/sms/models/v1/deliveryreports/EncodingType.java | 2 ++ .../sdk/domains/sms/models/v1/inbounds/BinaryMessage.java | 5 ++++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java index 4bfcc1c9d..2db7675a9 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/batches/request/UpdateBinaryRequest.java @@ -30,7 +30,10 @@ public interface UpdateBinaryRequest extends UpdateBatchRequest { */ String getFrom(); - /** SMS in binary format */ + /** + * SMS in binary + * format. + */ public class TypeEnum extends EnumDynamic { public static final TypeEnum MT_BINARY = new TypeEnum("mt_binary"); diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java index eddb456a8..ab79efa65 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/deliveryreports/EncodingType.java @@ -8,8 +8,10 @@ /** Applied encoding for message. Present only if smart encoding is enabled. */ public class EncodingType extends EnumDynamic { + /** GSM enconding. */ public static final EncodingType GSM = new EncodingType("GSM"); + /** Unicode encoding. */ public static final EncodingType UNICODE = new EncodingType("UNICODE"); private static final EnumSupportDynamic ENUM_SUPPORT = diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java index b01a05724..79f588b59 100644 --- a/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/sms/models/v1/inbounds/BinaryMessage.java @@ -79,7 +79,10 @@ public interface BinaryMessage extends InboundMessage { */ String getTo(); - /** SMS in binary format */ + /** + * SMS in binary + * format. + */ public class TypeEnum extends EnumDynamic { public static final TypeEnum MO_BINARY = new TypeEnum("mo_binary"); From f6a4a0c949272de83398bc973b917d3070b60b41 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Mon, 27 Jan 2025 12:51:44 +0100 Subject: [PATCH 62/65] chore (Jackson): Update Jackson dependency from 'jackson-jaxrs-json-provider:2.15.2' to 'jackson-jakarta-rs-json-provider:2.18.2' --- README.md | 88 +++++++++++++++++++++++++++++++++++++++++++++---------- pom.xml | 6 ++-- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 2990c4f84..7eb76558d 100644 --- a/README.md +++ b/README.md @@ -61,37 +61,93 @@ SinchClient client = new SinchClient(configuration); Here is the list of the Sinch products and their level of support by the Java SDK: -| API Category | API Name | Status | -|------------------------|-------------------------------------------------------------------------------------------------------------------------------------|:------:| -| Conversation | Conversation API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/conversation/package-summary.html) | ✅ | -| Messaging | SMS API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/sms/package-summary.html) | ✅ | -| Numbers & Connectivity | Numbers API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/numbers/package-summary.html) | ✅ | -| Verification | Verification API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/verification/package-summary.html) | ✅ | -| Voice and Video | Voice API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/package-summary.html) | ✅ | +| API Category | API Name | Status | +|------------------------|--------------------------------------------------------------------------------------------------------------------------------------|:------:| +| Conversation | Conversation API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/conversation/package-summary.html) | ✅ | +| Messaging | SMS API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/sms/package-summary.html) | ✅ | +| Numbers & Connectivity | Numbers API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/numbers/package-summary.html) | ✅ | +| Verification | Verification API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/verification/package-summary.html) | ✅ | +| Voice and Video | Voice API [(javadoc)](https://developers.sinch.com/java-sdk/apidocs/com/sinch/sdk/domains/voice/package-summary.html) | ✅ | ## Logging -The SDK uses the Java 8 logging feature ([java.util.logging](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html)) -Loggers and severity can be configured by using a `logging.properties` file like (see sample-app/src/main/resources/: +The SDK uses the Java 8 logging feature ([java.util.logging](https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html#package.description)) + +When using java logging, Loggers and severity can be configured by using a `logging.properties` file like: ``` -handlers = java.util.logging.ConsoleHandler -java.util.logging.ConsoleHandler.level = INFO -com.sinch.sdk.level = INFO +# java.util.logging configuration sample +# See https://docs.oracle.com/javase/8/docs/api/java/util/logging/package-summary.html#package.description + +# +# Layers logging severity configuration +# + +# Sinch SDK +com.sinch.level = INFO + +# Apache HTTP Client +# org.apache.hc.level = + +# +# console output handler sample +# +handlers = java.util.logging.ConsoleHandler java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s %2$s] %5$s %n +java.util.logging.ConsoleHandler.level = FINEST ``` +If using another logging framework (SL4F, Spring) see your framework documentation ## Onboarding To improve onboarding experience, following resources are available: -- Sinch developpers online doucmentation: https://developers.sinch.com +- Sinch's developers online documentation: https://developers.sinch.com - A dedicated Java SDK quickstart repository with tutorials and templates enabling to start quickly a new project: https://github.com/sinch/sinch-sdk-java-quickstart -- A dedicated Java SDK sippets repository with basic code snippets: https://github.com/sinch/sinch-sdk-java-snippets -- Java SDK online javdoc: https://developers.sinch.com/java-sdk/apidocs +- A dedicated Java SDK snippets repository with basic code snippets: https://github.com/sinch/sinch-sdk-java-snippets +- Java SDK online javadoc: https://developers.sinch.com/java-sdk/apidocs + +## 3rd party dependencies +SDK's third party dependencies are: +- [Jackson's library](https://github.com/FasterXML/jackson-jakarta-rs-providers) for JSON serialization/deserialization features +- [Apache HTTP client](https://hc.apache.org/httpcomponents-client-5.4.x/5.4.1/httpclient5/project-info.html) to handle communication with Sinch products/REST APIs + +### Jackson/JavaEE/jaxrs/jakarta conflict consideration +jakarta namespace used by Jackson could cause issue following migration from javax with Java EE transition (see [Oracle site note about transition](https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee) for details) + +Following notes for Jackson maintainers, there is 2 Jackson available versions. +> (*) NOTE: Jakarta-RS is the package under jakarta.ws.rs, replacing older JAX-RS which lived under javax.ws.rs. For JAX-RS variant, see repo jackson-jaxrs-providers + +By default, Sinch SDK Java is using "new" [jackson-jakarta-rs-providers](https://github.com/FasterXML/jackson-jakarta-rs-providers) but you could switch to "old" [jackson-jaxrs-providers](https://github.com/FasterXML/jackson-jaxrs-providers) if required. +#### Switching to jackson-jaxrs-providers +According to your use case, dependencies could have to be tuned if you need jaxrs usage. +Add following to your dependency list: +Note: Replace VERSION-YOU-WANT-TO-BE-USED by a Jackson minimal version of `2.15.2` +```xml +... + + com.sinch.sdk + sinch-sdk-java + ${sinch.sdk.java.version} + + + com.fasterxml.jackson.jaxrs + jackson-jakarta-rs-json-provider + + + + + com.fasterxml.jackson.jakarta.rs + jackson-jaxrs-json-provider + VERSION-YOU-WANT-TO-BE-USED + +... +``` ## License -This project is licensed under the Apache License. See the [LICENSE](LICENSE) file for the license text. +This project is licensed under the Apache License. + +See the [LICENSE](LICENSE) file for the license text. diff --git a/pom.xml b/pom.xml index 267ebdc2e..68a0dbc2f 100644 --- a/pom.xml +++ b/pom.xml @@ -67,7 +67,7 @@ UTF-8 - 2.15.2 + 2.18.2 5.2.1 @@ -420,8 +420,8 @@ - com.fasterxml.jackson.jaxrs - jackson-jaxrs-json-provider + com.fasterxml.jackson.jakarta.rs + jackson-jakarta-rs-json-provider ${jackson.version} From ef5267fd02ce3ab14b40b9f17c88704c01e0a9a0 Mon Sep 17 00:00:00 2001 From: Antoine SEIN <142824551+asein-sinch@users.noreply.github.com> Date: Mon, 27 Jan 2025 22:10:33 +0100 Subject: [PATCH 63/65] Rephrase documentation --- README.md | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 7eb76558d..79f4f3f07 100644 --- a/README.md +++ b/README.md @@ -98,34 +98,34 @@ java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter java.util.logging.SimpleFormatter.format=[%1$tF %1$tT] [%4$-7s %2$s] %5$s %n java.util.logging.ConsoleHandler.level = FINEST ``` -If using another logging framework (SL4F, Spring) see your framework documentation +If you are using a different logging framework (such as SLF4J or Spring), please refer to the documentation for your specific framework. ## Onboarding -To improve onboarding experience, following resources are available: -- Sinch's developers online documentation: https://developers.sinch.com -- A dedicated Java SDK quickstart repository with tutorials and templates enabling to start quickly a new project: https://github.com/sinch/sinch-sdk-java-quickstart -- A dedicated Java SDK snippets repository with basic code snippets: https://github.com/sinch/sinch-sdk-java-snippets -- Java SDK online javadoc: https://developers.sinch.com/java-sdk/apidocs +To enhance the onboarding experience, the following resources are available: +- **Sinch Online Developers Documentation**: https://developers.sinch.com +- **Java SDK Quickstart Repository**: A repository with tutorials and templates to help you quickly start a new project: https://github.com/sinch/sinch-sdk-java-quickstart +- **Java SDK Snippets Repository**: A collection of basic code snippets for reference: https://github.com/sinch/sinch-sdk-java-snippets +- **Java SDK Online Javadoc**: https://developers.sinch.com/java-sdk/apidocs ## 3rd party dependencies -SDK's third party dependencies are: -- [Jackson's library](https://github.com/FasterXML/jackson-jakarta-rs-providers) for JSON serialization/deserialization features -- [Apache HTTP client](https://hc.apache.org/httpcomponents-client-5.4.x/5.4.1/httpclient5/project-info.html) to handle communication with Sinch products/REST APIs +The SDK relies on the following third-party dependencies: +- [Jackson's library](https://github.com/FasterXML/jackson-jakarta-rs-providers): Provides JSON serialization/deserialization functionality. +- [Apache HTTP client](https://hc.apache.org/httpcomponents-client-5.4.x/5.4.1/httpclient5/project-info.html): Manages communication with Sinch products' REST APIs -### Jackson/JavaEE/jaxrs/jakarta conflict consideration -jakarta namespace used by Jackson could cause issue following migration from javax with Java EE transition (see [Oracle site note about transition](https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee) for details) +### Jackson/Java EE/jaxrs/Jakarta Compatibility Consideration +The transition from javax to jakarta namespaces with the Java EE to Jakarta EE migration may cause compatibility issues. Refer to [Oracle's note about the transition](https://blogs.oracle.com/javamagazine/post/transition-from-java-ee-to-jakarta-ee) for additional details. -Following notes for Jackson maintainers, there is 2 Jackson available versions. +Jackson maintainers provide two variants of the library: > (*) NOTE: Jakarta-RS is the package under jakarta.ws.rs, replacing older JAX-RS which lived under javax.ws.rs. For JAX-RS variant, see repo jackson-jaxrs-providers -By default, Sinch SDK Java is using "new" [jackson-jakarta-rs-providers](https://github.com/FasterXML/jackson-jakarta-rs-providers) but you could switch to "old" [jackson-jaxrs-providers](https://github.com/FasterXML/jackson-jaxrs-providers) if required. +By default, the Sinch Java SDK uses the "new" [jackson-jakarta-rs-providers](https://github.com/FasterXML/jackson-jakarta-rs-providers). However, you can switch to the "older" [jackson-jaxrs-providers](https://github.com/FasterXML/jackson-jaxrs-providers) if required. #### Switching to jackson-jaxrs-providers -According to your use case, dependencies could have to be tuned if you need jaxrs usage. +Depending on your use case, you may need to adjust dependencies to enable jaxrs usage. -Add following to your dependency list: -Note: Replace VERSION-YOU-WANT-TO-BE-USED by a Jackson minimal version of `2.15.2` +Add the following dependency to your configuration: +Note: Replace VERSION-YOU-WANT-TO-BE-USED by a Jackson version of at least `2.15.2`. ```xml ... From ceb4ce556079b0b116eff7291345a01db7f3f1a2 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 28 Jan 2025 06:44:28 +0100 Subject: [PATCH 64/65] docs (README): Update TOC --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79f4f3f07..e7375329c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,10 @@ For more information on the Sinch APIs on which this SDK is based, refer to the - [Prerequisites](#prerequisites) - [Installation](#installation) - [Getting started](#getting-started) -- [Logging]() +- [Supported APIs](#supported-apis) +- [Logging](#logging) +- [Onboarding](#onboarding) +- [3rd party dependencies](#3rd-party-dependencies) ## Prerequisites @@ -57,7 +60,7 @@ Configuration configuration = Configuration.builder().setKeyId(PARAM_KEY_ID) SinchClient client = new SinchClient(configuration); ``` -## Products +## Supported APIs Here is the list of the Sinch products and their level of support by the Java SDK: From 018b00299114674c8095d6656df9b90a6fdc092f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 28 Jan 2025 06:53:59 +0100 Subject: [PATCH 65/65] docs (README): rendering updates --- README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index e7375329c..a34e88f8c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,9 @@ Once the SDK is installed, you must start by initializing the main client class. ### Client initialization -To initialize communication with the Sinch servers, credentials obtained from the Sinch dashboard must be provided to the main client class of this SDK. It's highly recommended to not hardcode these credentials and to load them from environment variables instead. +To initialize communication with the Sinch servers, credentials obtained from the Sinch dashboard must be provided to the main client class of this SDK. + +It's highly recommended to not hardcode these credentials and to load them from environment variables instead. Sample: @@ -52,10 +54,11 @@ import com.sinch.sdk.SinchClient; import com.sinch.sdk.models.Configuration; ... -Configuration configuration = Configuration.builder().setKeyId(PARAM_KEY_ID) - .setKeySecret(PARAM_KEY_SECRET) - .setProjectId(PARAM_PROJECT_ID) - .build(); +Configuration configuration = Configuration.builder() + .setKeyId(PARAM_KEY_ID) + .setKeySecret(PARAM_KEY_SECRET) + .setProjectId(PARAM_PROJECT_ID) + .build(); ... SinchClient client = new SinchClient(configuration); ``` @@ -106,10 +109,10 @@ If you are using a different logging framework (such as SLF4J or Spring), please ## Onboarding To enhance the onboarding experience, the following resources are available: -- **Sinch Online Developers Documentation**: https://developers.sinch.com -- **Java SDK Quickstart Repository**: A repository with tutorials and templates to help you quickly start a new project: https://github.com/sinch/sinch-sdk-java-quickstart -- **Java SDK Snippets Repository**: A collection of basic code snippets for reference: https://github.com/sinch/sinch-sdk-java-snippets -- **Java SDK Online Javadoc**: https://developers.sinch.com/java-sdk/apidocs +- Sinch Online Developers Documentation: https://developers.sinch.com +- Java SDK Online Javadoc: https://developers.sinch.com/java-sdk/apidocs +- Java SDK Quickstart Repository: A repository with tutorials and templates to help you quickly start a new project: https://github.com/sinch/sinch-sdk-java-quickstart +- Java SDK Snippets Repository: A collection of basic code snippets for reference: https://github.com/sinch/sinch-sdk-java-snippets ## 3rd party dependencies The SDK relies on the following third-party dependencies: