diff --git a/client/src/main/com/sinch/sdk/domains/conversation/ConversationService.java b/client/src/main/com/sinch/sdk/domains/conversation/ConversationService.java index 317f075e..309c50cc 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/ConversationService.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/ConversationService.java @@ -1,5 +1,7 @@ package com.sinch.sdk.domains.conversation; +import com.sinch.sdk.domains.conversation.api.templates.TemplatesService; + /** * Conversation Service * @@ -15,7 +17,21 @@ public interface ConversationService { * @return V1 service instance for project * @see Documentation - * @since 1.2 + * @since _NEXT_VERSION_ */ com.sinch.sdk.domains.conversation.api.v1.ConversationService v1(); + + /** + * Templates service + * + *

The Template Management API offers a way to manage templates that can be used together with + * the Conversation API. Note that you may also use the Message Composer tool on the Sinch + * Customer Dashboard to manage templates. + * + * @return Service instance for project + * @see Documentation + * @since _NEXT_VERSION_ + */ + TemplatesService templates(); } diff --git a/client/src/main/com/sinch/sdk/domains/conversation/adapters/ConversationService.java b/client/src/main/com/sinch/sdk/domains/conversation/adapters/ConversationService.java index 961d1d5b..2341fc74 100644 --- a/client/src/main/com/sinch/sdk/domains/conversation/adapters/ConversationService.java +++ b/client/src/main/com/sinch/sdk/domains/conversation/adapters/ConversationService.java @@ -2,25 +2,44 @@ import com.sinch.sdk.core.http.HttpClient; import com.sinch.sdk.core.models.ServerConfiguration; +import com.sinch.sdk.domains.conversation.api.templates.adapters.TemplatesService; import com.sinch.sdk.models.ConversationContext; import com.sinch.sdk.models.UnifiedCredentials; public class ConversationService implements com.sinch.sdk.domains.conversation.ConversationService { - private final com.sinch.sdk.domains.conversation.api.v1.ConversationService v1; + private final UnifiedCredentials credentials; + private final ConversationContext context; + private final ServerConfiguration oAuthServer; + private final HttpClient httpClient; + + private com.sinch.sdk.domains.conversation.api.v1.ConversationService conversationV1; + private TemplatesService templates; public ConversationService( UnifiedCredentials credentials, ConversationContext context, ServerConfiguration oAuthServer, HttpClient httpClient) { - - this.v1 = - new com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationService( - credentials, context, oAuthServer, httpClient); + this.credentials = credentials; + this.context = context; + this.oAuthServer = oAuthServer; + this.httpClient = httpClient; } public com.sinch.sdk.domains.conversation.api.v1.ConversationService v1() { - return v1; + if (null == this.conversationV1) { + this.conversationV1 = + new com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationService( + credentials, context, oAuthServer, httpClient); + } + return this.conversationV1; + } + + public TemplatesService templates() { + if (null == this.templates) { + this.templates = new TemplatesService(credentials, context, oAuthServer, httpClient); + } + return this.templates; } } diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/templates/TemplatesService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/TemplatesService.java new file mode 100644 index 00000000..11a98d20 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/TemplatesService.java @@ -0,0 +1,31 @@ +package com.sinch.sdk.domains.conversation.api.templates; + +import com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; + +/** + * Service for working with templates + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface TemplatesService { + + /** + * Service for working with templates V1 + * + * @return Templates V1 service + * @since _NEXT_VERSION_ + */ + TemplatesServiceV1 v1(); + + /** + * Service for working with templates V2 + * + * @return Templates V2 service + * @since _NEXT_VERSION_ + */ + TemplatesServiceV2 v2(); +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplatesService.java b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplatesService.java new file mode 100644 index 00000000..1f44085a --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplatesService.java @@ -0,0 +1,106 @@ +package com.sinch.sdk.domains.conversation.api.templates.adapters; + +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.domains.conversation.api.templates.adapters.v1.TemplatesServiceV1; +import com.sinch.sdk.domains.conversation.api.templates.adapters.v2.TemplatesServiceV2; +import com.sinch.sdk.domains.conversation.api.v1.adapters.ConversationService; +import com.sinch.sdk.domains.conversation.templates.models.v2.ChannelTemplateOverrideMapper; +import com.sinch.sdk.models.ConversationContext; +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 TemplatesService + implements com.sinch.sdk.domains.conversation.api.templates.TemplatesService { + + private static final Logger LOGGER = Logger.getLogger(TemplatesService.class.getName()); + private static final String SECURITY_SCHEME_KEYWORD_ = "oAuth2"; + + private final String uriUUID; + private final ConversationContext context; + private final HttpClient httpClient; + private final Map authManagers; + private TemplatesServiceV1 v1; + private TemplatesServiceV2 v2; + + static { + LocalLazyInit.init(); + } + + public TemplatesService( + UnifiedCredentials credentials, + ConversationContext context, + ServerConfiguration oAuthServer, + HttpClient httpClient) { + + Objects.requireNonNull(credentials, "Templates service requires credentials to be defined"); + Objects.requireNonNull(context, "Templates service requires context to be defined"); + StringUtil.requireNonEmpty( + credentials.getKeyId(), "Templates service requires 'keyId' to be defined"); + StringUtil.requireNonEmpty( + credentials.getKeySecret(), "Templates service requires 'keySecret' to be defined"); + StringUtil.requireNonEmpty( + credentials.getProjectId(), "Templates service requires 'projectId' to be defined"); + + StringUtil.requireNonEmpty( + context.getTemplateManagementUrl(), + "Templates service requires 'templateManagementUrl' to be defined"); + + LOGGER.fine( + String.format( + "Activate templates API with template server: '%s", + context.getTemplateManagementServer().getUrl())); + + this.uriUUID = credentials.getProjectId(); + this.context = context; + this.httpClient = httpClient; + + OAuthManager authManager = + new OAuthManager(credentials, oAuthServer, new HttpMapper(), httpClient); + authManagers = + Stream.of(new AbstractMap.SimpleEntry<>(SECURITY_SCHEME_KEYWORD_, authManager)) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + public TemplatesServiceV1 v1() { + if (null == this.v1) { + this.v1 = new TemplatesServiceV1(uriUUID, context, httpClient, authManagers); + } + return this.v1; + } + + public TemplatesServiceV2 v2() { + if (null == this.v2) { + this.v2 = new TemplatesServiceV2(uriUUID, context, httpClient, authManagers); + } + return this.v2; + } + + static final class LocalLazyInit { + + private LocalLazyInit() { + // Because of templates classes are depending of Conversation classes we need to init for a + // proper serialize/deserialize process + ConversationService.LocalLazyInit.init(); + ChannelTemplateOverrideMapper.initMapper(); + } + + public static LocalLazyInit init() { + return LocalLazyInit.LazyHolder.INSTANCE; + } + + private static class LazyHolder { + + public static final LocalLazyInit INSTANCE = new LocalLazyInit(); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/v1/TemplatesServiceV1.java b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/v1/TemplatesServiceV1.java new file mode 100644 index 00000000..20441e4c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/v1/TemplatesServiceV1.java @@ -0,0 +1,52 @@ +package com.sinch.sdk.domains.conversation.api.templates.adapters.v1; + +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.conversation.templates.api.internal.TemplatesV1Api; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import com.sinch.sdk.models.ConversationContext; +import java.util.Collection; +import java.util.Map; + +public class TemplatesServiceV1 + implements com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1 { + + private final String uriUUID; + private final TemplatesV1Api api; + + public TemplatesServiceV1( + String uriUUID, + ConversationContext context, + HttpClient httpClient, + Map authManagers) { + this.uriUUID = uriUUID; + this.api = + new TemplatesV1Api( + httpClient, context.getTemplateManagementServer(), authManagers, new HttpMapper()); + } + + protected TemplatesV1Api getApi() { + return this.api; + } + + public Collection list() { + return getApi().templatesListTemplates(uriUUID).getTemplates(); + } + + public TemplateV1 create(TemplateV1 template) { + return getApi().templatesCreateTemplate(uriUUID, template); + } + + public TemplateV1 get(String templateId) { + return getApi().templatesGetTemplate(uriUUID, templateId); + } + + public void delete(String templateId) { + getApi().templatesDeleteTemplate(uriUUID, templateId); + } + + public TemplateV1 update(String templateId, TemplateV1 template) { + return getApi().templatesUpdateTemplate(uriUUID, templateId, template, null); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/v2/TemplatesServiceV2.java b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/v2/TemplatesServiceV2.java new file mode 100644 index 00000000..df114fc5 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/adapters/v2/TemplatesServiceV2.java @@ -0,0 +1,76 @@ +package com.sinch.sdk.domains.conversation.api.templates.adapters.v2; + +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.conversation.templates.api.internal.TemplatesV2Api; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTranslationsResponseInternal; +import com.sinch.sdk.domains.conversation.templates.models.v2.request.TranslationListRequest; +import com.sinch.sdk.models.ConversationContext; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +public class TemplatesServiceV2 + implements com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2 { + + private final String uriUUID; + private final TemplatesV2Api api; + + public TemplatesServiceV2( + String uriUUID, + ConversationContext context, + HttpClient httpClient, + Map authManagers) { + this.uriUUID = uriUUID; + this.api = + new TemplatesV2Api( + httpClient, context.getTemplateManagementServer(), authManagers, new HttpMapper()); + } + + protected TemplatesV2Api getApi() { + return this.api; + } + + public Collection list() { + return getApi().templatesV2ListTemplates(uriUUID).getTemplates(); + } + + public Collection listTranslations( + String templateId, TranslationListRequest request) { + + if (null == request) { + request = TranslationListRequest.builder().build(); + } + String languageCode = request.getLanguageCode().orElse(null); + String translationVersion = request.getTranslationVersion().orElse(null); + + V2ListTranslationsResponseInternal response = + getApi().templatesV2ListTranslations(uriUUID, templateId, languageCode, translationVersion); + if (null == response || null == response.getTranslations()) { + return Collections.emptyList(); + } + return response.getTranslations().stream() + .map(TemplateTranslation::from) + .collect(Collectors.toList()); + } + + public TemplateV2 create(TemplateV2 template) { + return getApi().templatesV2CreateTemplate(uriUUID, template); + } + + public TemplateV2 get(String templateId) { + return getApi().templatesV2GetTemplate(uriUUID, templateId); + } + + public void delete(String templateId) { + getApi().templatesV2DeleteTemplate(uriUUID, templateId); + } + + public TemplateV2 update(String templateId, TemplateV2 template) { + return getApi().templatesV2UpdateTemplate(uriUUID, templateId, template); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.java b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.java new file mode 100644 index 00000000..19ed4524 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/v1/TemplatesServiceV1.java @@ -0,0 +1,59 @@ +package com.sinch.sdk.domains.conversation.api.templates.v1; + +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import java.util.Collection; + +/** + * Templates V1 + * + *

Version 1 endpoints for managing message templates. Currently maintained for existing users. + * Version 2 is recommended. + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface TemplatesServiceV1 { + + /** + * List all templates belonging to a project ID. + * + * @return List of templates * @since _NEXT_VERSION_ + * @since _NEXT_VERSION_ + */ + Collection list(); + + /** + * Creates a template + * + * @param template Information for creation + * @return Created template + * @since _NEXT_VERSION_ + */ + TemplateV1 create(TemplateV1 template); + + /*** + * Get a template + * @param templateId The ID of the template to fetch. + * @return The template information + * @since _NEXT_VERSION_ + */ + TemplateV1 get(String templateId); + + /*** + * Delete a template + * @param templateId The ID of the template to delete. + * @since _NEXT_VERSION_ + */ + void delete(String templateId); + + /** + * Updates a template + * + * @param template Information to be updated + * @return Updated template + * @since _NEXT_VERSION_ + */ + TemplateV1 update(String templateId, TemplateV1 template); +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.java b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.java new file mode 100644 index 00000000..8ea15f60 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/api/templates/v2/TemplatesServiceV2.java @@ -0,0 +1,69 @@ +package com.sinch.sdk.domains.conversation.api.templates.v2; + +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import com.sinch.sdk.domains.conversation.templates.models.v2.request.TranslationListRequest; +import java.util.Collection; + +/** + * Templates V2 + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface TemplatesServiceV2 { + + /** + * List all templates belonging to a project ID. + * + * @return List of templates + * @since _NEXT_VERSION_ + */ + Collection list(); + + /** + * List translations for a template + * + * @param templateId The ID of the template to fetch + * @param request Parameters for request + * @return The translations list + * @since _NEXT_VERSION_ + */ + Collection listTranslations( + String templateId, TranslationListRequest request); + + /** + * Creates a template + * + * @param template Information for creation + * @return Created template + * @since _NEXT_VERSION_ + */ + TemplateV2 create(TemplateV2 template); + + /*** + * Get a template + * @param templateId The ID of the template to fetch. + * @return The template information + * @since _NEXT_VERSION_ + */ + TemplateV2 get(String templateId); + + /*** + * Delete a template + * @param templateId The ID of the template to delete. + * @since _NEXT_VERSION_ + */ + void delete(String templateId); + + /** + * Updates a template + * + * @param template Information to be updated + * @return Updated template + * @since _NEXT_VERSION_ + */ + TemplateV2 update(String templateId, TemplateV2 template); +} 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 9aa2e945..96ec9192 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 @@ -6,6 +6,7 @@ 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.conversation.api.templates.adapters.TemplatesService; import com.sinch.sdk.domains.conversation.api.v1.adapters.events.app.AppEventMapper; import com.sinch.sdk.domains.conversation.api.v1.adapters.events.contactmessage.internal.ContactMessageEventMapper; import com.sinch.sdk.domains.conversation.api.v1.adapters.events.contacts.internal.ContactEventMapper; @@ -23,6 +24,7 @@ import com.sinch.sdk.domains.conversation.models.v1.messages.types.carousel.CarouselMessageMapper; import com.sinch.sdk.domains.conversation.models.v1.messages.types.internal.ChoiceMessageMapper; import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessageMapper; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslationMapper; import com.sinch.sdk.models.ConversationContext; import com.sinch.sdk.models.UnifiedCredentials; import java.util.AbstractMap; @@ -39,6 +41,8 @@ public class ConversationService private static final String SECURITY_SCHEME_KEYWORD_ = "oAuth2"; private final String uriUUID; + private final UnifiedCredentials credentials; + private final ServerConfiguration oAuthServer; private final ConversationContext context; private final HttpClient httpClient; private final Map authManagers; @@ -50,6 +54,7 @@ public class ConversationService private TranscodingService transcoding; private CapabilityService capability; private WebHooksService webhooks; + private TemplatesService templates; static { LocalLazyInit.init(); @@ -71,18 +76,15 @@ public ConversationService( credentials.getProjectId(), "Conversation service requires 'projectId' to be defined"); StringUtil.requireNonEmpty( context.getUrl(), "Conversation service requires 'url' to be defined"); - StringUtil.requireNonEmpty( - context.getTemplateManagementUrl(), - "Conversation service requires 'templateManagementUrl' to be defined"); LOGGER.fine( - String.format( - "Activate conversation API with server: '%s', template server: '%s", - context.getServer().getUrl(), context.getTemplateManagementServer().getUrl())); + String.format("Activate conversation API with server: '%s'", context.getServer().getUrl())); this.uriUUID = credentials.getProjectId(); + this.credentials = credentials; this.context = context; this.httpClient = httpClient; + this.oAuthServer = oAuthServer; OAuthManager authManager = new OAuthManager(credentials, oAuthServer, new HttpMapper(), httpClient); @@ -153,7 +155,14 @@ public CapabilityService capability() { return this.capability; } - static final class LocalLazyInit { + public TemplatesService templates() { + if (null == this.templates) { + this.templates = new TemplatesService(credentials, context, oAuthServer, httpClient); + } + return this.templates; + } + + public static final class LocalLazyInit { private LocalLazyInit() { AppEventMapper.initMapper(); @@ -173,6 +182,7 @@ private LocalLazyInit() { RecipientMapper.initMapper(); SendMessageRequestMapper.initMapper(); TemplateMessageMapper.initMapper(); + TemplateTranslationMapper.initMapper(); WhatsAppInteractiveHeaderMapper.initMapper(); } diff --git a/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverrideMapper.java b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverrideMapper.java new file mode 100644 index 00000000..0203deee --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverrideMapper.java @@ -0,0 +1,39 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +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.TemplateReference; +import com.sinch.sdk.domains.conversation.models.v1.TemplateReferenceImpl; + +public class ChannelTemplateOverrideMapper { + + public static void initMapper() { + + Mapper.getInstance() + .addMixIn(ChannelTemplateOverride.class, ChannelTemplateOverrideMapperMixinSerializer.class) + .addMixIn( + ChannelTemplateOverride.Builder.class, ChannelTemplateOverrideBuilderMapperMixin.class); + } + + static class ChannelTemplateOverrideMapperMixinSerializer extends ChannelTemplateOverrideImpl { + + @Override + @JsonSerialize(using = TemplateReferenceImpl.DelegatedSerializer.class) + public OptionalValue templateReference() { + return super.templateReference(); + } + } + + static class ChannelTemplateOverrideBuilderMapperMixin + extends ChannelTemplateOverrideImpl.Builder { + + @Override + @JsonDeserialize(using = TemplateReferenceImpl.DelegatedDeSerializer.class) + public ChannelTemplateOverrideImpl.Builder setTemplateReference( + TemplateReference templateReference) { + return super.setTemplateReference(templateReference); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslation.java b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslation.java new file mode 100644 index 00000000..44fb428c --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslation.java @@ -0,0 +1,48 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessageBody; + +/** Message to be injected */ +public interface TemplateTranslation extends TemplateTranslationBase { + + /** + * Get translation message + * + * @return Body message + */ + AppMessageBody getMessage(); + + /** + * Getting builder + * + * @return New Builder instance + */ + @SuppressWarnings("rawtypes") + static Builder builder() { + return new TemplateTranslationImpl.Builder(); + } + + static TemplateTranslation from(TemplateTranslationBase from) { + return new TemplateTranslationImpl(from); + } + + /** Dedicated Builder */ + interface Builder> extends TemplateTranslationBase.Builder { + + /** + * see getter + * + * @param message see getter + * @return Current builder + * @see #getMessage() + */ + B setMessage(AppMessageBody message); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TemplateTranslation build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationImpl.java b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationImpl.java new file mode 100644 index 00000000..c1204af7 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationImpl.java @@ -0,0 +1,159 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.sinch.sdk.core.models.OptionalValue; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.messages.AppMessageBody; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.card.CardMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.carousel.CarouselMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.choice.ChoiceMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.contactinfo.ContactInfoMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.list.ListMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.location.LocationMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.media.MediaMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.logging.Logger; + +public class TemplateTranslationImpl extends TemplateTranslationBaseImpl + implements TemplateTranslation { + + private static final Logger LOGGER = Logger.getLogger(TemplateTranslationImpl.class.getName()); + + TemplateTranslationImpl(TemplateTranslationBase _from) { + super( + ((TemplateTranslationBaseImpl) _from).languageCode(), + ((TemplateTranslationBaseImpl) _from).version(), + ((TemplateTranslationBaseImpl) _from).channelTemplateOverrides(), + ((TemplateTranslationBaseImpl) _from).variables(), + ((TemplateTranslationBaseImpl) _from).createTime(), + ((TemplateTranslationBaseImpl) _from).updateTime(), + ((TemplateTranslationBaseImpl) _from).cardMessage(), + ((TemplateTranslationBaseImpl) _from).carouselMessage(), + ((TemplateTranslationBaseImpl) _from).choiceMessage(), + ((TemplateTranslationBaseImpl) _from).locationMessage(), + ((TemplateTranslationBaseImpl) _from).mediaMessage(), + ((TemplateTranslationBaseImpl) _from).templateMessage(), + ((TemplateTranslationBaseImpl) _from).textMessage(), + ((TemplateTranslationBaseImpl) _from).listMessage(), + ((TemplateTranslationBaseImpl) _from).contactInfoMessage()); + } + + @JsonIgnore + public AppMessageBody getMessage() { + + if (cardMessage().isPresent()) { + return cardMessage().get(); + } else if (carouselMessage().isPresent()) { + return carouselMessage().get(); + } else if (choiceMessage().isPresent()) { + return choiceMessage().get(); + } else if (contactInfoMessage().isPresent()) { + return contactInfoMessage().get(); + } else if (listMessage().isPresent()) { + return listMessage().get(); + } else if (locationMessage().isPresent()) { + return locationMessage().get(); + } else if (mediaMessage().isPresent()) { + return mediaMessage().get(); + } else if (templateMessage().isPresent()) { + return templateMessage().get(); + } else if (textMessage().isPresent()) { + return textMessage().get(); + } + return null; + } + + protected TemplateTranslationImpl( + OptionalValue languageCode, + OptionalValue version, + OptionalValue> channelTemplateOverrides, + OptionalValue> variables, + OptionalValue createTime, + OptionalValue updateTime, + OptionalValue cardMessage, + OptionalValue carouselMessage, + OptionalValue choiceMessage, + OptionalValue locationMessage, + OptionalValue mediaMessage, + OptionalValue templateMessage, + OptionalValue textMessage, + OptionalValue listMessage, + OptionalValue contactInfoMessage) { + super( + languageCode, + version, + channelTemplateOverrides, + variables, + createTime, + updateTime, + cardMessage, + carouselMessage, + choiceMessage, + locationMessage, + mediaMessage, + templateMessage, + textMessage, + listMessage, + contactInfoMessage); + } + + static class Builder> extends TemplateTranslationBaseImpl.Builder + implements TemplateTranslation.Builder { + + public B setMessage(AppMessageBody message) { + + if (message instanceof CardMessage) { + this.cardMessage = OptionalValue.of((CardMessage) message); + } else if (message instanceof CarouselMessage) { + this.carouselMessage = OptionalValue.of((CarouselMessage) message); + } else if (message instanceof ChoiceMessage) { + this.choiceMessage = OptionalValue.of((ChoiceMessage) message); + } else if (message instanceof ContactInfoMessage) { + this.contactInfoMessage = OptionalValue.of((ContactInfoMessage) message); + } else if (message instanceof ListMessage) { + this.listMessage = OptionalValue.of((ListMessage) message); + } else if (message instanceof LocationMessage) { + this.locationMessage = OptionalValue.of((LocationMessage) message); + } else if (message instanceof MediaMessage) { + this.mediaMessage = OptionalValue.of((MediaMessage) message); + } else if (message instanceof TemplateMessage) { + this.templateMessage = OptionalValue.of((TemplateMessage) message); + } else if (message instanceof TextMessage) { + this.textMessage = OptionalValue.of((TextMessage) message); + } else { + LOGGER.severe("Unexpected message: " + message); + } + return self(); + } + + @Override + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + public TemplateTranslation build() { + return new TemplateTranslationImpl( + languageCode, + version, + channelTemplateOverrides, + variables, + createTime, + updateTime, + cardMessage, + carouselMessage, + choiceMessage, + locationMessage, + mediaMessage, + templateMessage, + textMessage, + listMessage, + contactInfoMessage); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationMapper.java b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationMapper.java new file mode 100644 index 00000000..0f74df03 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationMapper.java @@ -0,0 +1,159 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +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.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.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; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.contactinfo.ContactInfoMessageImpl; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.list.ListMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.list.ListMessageImpl; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.location.LocationMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.location.LocationMessageImpl; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.media.MediaMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.media.MediaMessageImpl; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessage; +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 com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslationBaseImpl.Builder; + +public class TemplateTranslationMapper { + + public static void initMapper() { + + Mapper.getInstance() + .addMixIn( + TemplateTranslationBase.class, TemplateTranslationInternalMapperMixinSerializer.class) + .addMixIn( + TemplateTranslationBase.Builder.class, + TemplateTranslationInternalBuilderMapperMixin.class); + } + + static class TemplateTranslationInternalMapperMixinSerializer + extends TemplateTranslationBaseImpl { + + @Override + @JsonSerialize(using = CardMessageImpl.DelegatedSerializer.class) + public OptionalValue cardMessage() { + return super.cardMessage(); + } + + @Override + @JsonSerialize(using = CarouselMessageMapper.DelegatedSerializer.class) + public OptionalValue carouselMessage() { + return super.carouselMessage(); + } + + @Override + @JsonSerialize(using = ChoiceMessageImpl.DelegatedSerializer.class) + public OptionalValue choiceMessage() { + return super.choiceMessage(); + } + + @Override + @JsonSerialize(using = ContactInfoMessageImpl.DelegatedSerializer.class) + public OptionalValue contactInfoMessage() { + return super.contactInfoMessage(); + } + + @Override + @JsonSerialize(using = ListMessageImpl.DelegatedSerializer.class) + public OptionalValue listMessage() { + return super.listMessage(); + } + + @Override + @JsonSerialize(using = LocationMessageImpl.DelegatedSerializer.class) + public OptionalValue locationMessage() { + return super.locationMessage(); + } + + @Override + @JsonSerialize(using = MediaMessageImpl.DelegatedSerializer.class) + public OptionalValue mediaMessage() { + return super.mediaMessage(); + } + + @Override + @JsonSerialize( + using = + com.sinch.sdk.domains.conversation.models.v1.messages.types.template + .TemplateMessageMapper.DelegatedSerializer.class) + public OptionalValue templateMessage() { + return super.templateMessage(); + } + + @Override + @JsonSerialize(using = TextMessageImpl.DelegatedSerializer.class) + public OptionalValue textMessage() { + return super.textMessage(); + } + } + + static class TemplateTranslationInternalBuilderMapperMixin> + extends TemplateTranslationBaseImpl.Builder { + + @Override + @JsonDeserialize(using = CardMessageImpl.DelegatedDeSerializer.class) + public B setCardMessage(CardMessage cardMessage) { + return super.setCardMessage(cardMessage); + } + + @Override + @JsonDeserialize(using = CarouselMessageMapper.DelegatedDeSerializer.class) + public B setCarouselMessage(CarouselMessage carouselMessage) { + return super.setCarouselMessage(carouselMessage); + } + + @Override + @JsonDeserialize(using = ChoiceMessageImpl.DelegatedDeSerializer.class) + public B setChoiceMessage(ChoiceMessage choiceMessage) { + return super.setChoiceMessage(choiceMessage); + } + + @Override + @JsonDeserialize(using = ContactInfoMessageImpl.DelegatedDeSerializer.class) + public B setContactInfoMessage(ContactInfoMessage contactInfoMessage) { + return super.setContactInfoMessage(contactInfoMessage); + } + + @Override + @JsonDeserialize(using = ListMessageImpl.DelegatedDeSerializer.class) + public B setListMessage(ListMessage listMessage) { + return super.setListMessage(listMessage); + } + + @Override + @JsonDeserialize(using = LocationMessageImpl.DelegatedDeSerializer.class) + public B setLocationMessage(LocationMessage locationMessage) { + return super.setLocationMessage(locationMessage); + } + + @Override + @JsonDeserialize(using = MediaMessageImpl.DelegatedDeSerializer.class) + public B setMediaMessage(MediaMessage mediaMessage) { + return super.setMediaMessage(mediaMessage); + } + + @Override + @JsonDeserialize(using = TextMessageImpl.DelegatedDeSerializer.class) + public B setTextMessage(TextMessage textMessage) { + return super.setTextMessage(textMessage); + } + + @Override + @JsonDeserialize( + using = + com.sinch.sdk.domains.conversation.models.v1.messages.types.template + .TemplateMessageMapper.DelegatedDeSerializer.class) + public B setTemplateMessage(TemplateMessage templateMessage) { + return super.setTemplateMessage(templateMessage); + } + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/request/TranslationListRequest.java b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/request/TranslationListRequest.java new file mode 100644 index 00000000..ebb71b7e --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/request/TranslationListRequest.java @@ -0,0 +1,55 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2.request; + +import java.util.Optional; + +/** + * Parameters request to list translation relate to a template + * + * @see online + * documentation + * @since _NEXT_VERSION_ + */ +public interface TranslationListRequest { + + /** + * The translation's language code. + * + * @return Language code. + */ + Optional getLanguageCode(); + + /** + * The translation's version + * + * @return Translation's version + */ + Optional getTranslationVersion(); + + static Builder builder() { + return new TranslationListRequestImpl.Builder(); + } + + interface Builder { + + /** + * see getter + * + * @param languageCode see getter + * @return Current builder + * @see #getLanguageCode() () + */ + Builder setLanguageCode(String languageCode); + + /** + * see getter + * + * @param translationVersion see getter + * @return Current builder + * @see #getTranslationVersion() () + */ + Builder setTranslationVersion(String translationVersion); + + TranslationListRequest build(); + } +} diff --git a/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/request/TranslationListRequestImpl.java b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/request/TranslationListRequestImpl.java new file mode 100644 index 00000000..a4a3fb55 --- /dev/null +++ b/client/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/request/TranslationListRequestImpl.java @@ -0,0 +1,53 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2.request; + +import com.sinch.sdk.domains.conversation.templates.models.v2.request.TranslationListRequest.Builder; +import java.util.Optional; + +public class TranslationListRequestImpl implements TranslationListRequest { + + final String languageCode; + final String translationVersion; + + public TranslationListRequestImpl(String languageCode, String translationVersion) { + this.languageCode = languageCode; + this.translationVersion = translationVersion; + } + + @Override + public Optional getLanguageCode() { + return Optional.ofNullable(languageCode); + } + + @Override + public Optional getTranslationVersion() { + return Optional.ofNullable(translationVersion); + } + + public static Builder builder() { + return new Builder(); + } + + public static class Builder implements TranslationListRequest.Builder { + + String languageCode; + String translationVersion; + + Builder() {} + + @Override + public Builder setLanguageCode(String languageCode) { + this.languageCode = languageCode; + return this; + } + + @Override + public Builder setTranslationVersion(String translationVersion) { + this.translationVersion = translationVersion; + return this; + } + + public TranslationListRequest build() { + return new TranslationListRequestImpl(languageCode, translationVersion); + } + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplateServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplateServiceTest.java new file mode 100644 index 00000000..ddf120c6 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplateServiceTest.java @@ -0,0 +1,141 @@ +package com.sinch.sdk.domains.conversation.api.templates.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.ConversationContext; +import com.sinch.sdk.models.UnifiedCredentials; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; + +class TemplateServiceTest { + + @Mock HttpClient httpClient; + + @Test + void doNotAcceptNullKey() { + UnifiedCredentials credentials = + UnifiedCredentials.builder().setKeyId(null).setKeySecret("foo").setProjectId("foo").build(); + ConversationContext context = ConversationContext.builder().build(); + ServerConfiguration server = new ServerConfiguration("foo"); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new TemplatesService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("keyId")); + } + + @Test + void doNotAcceptNullKeySecret() { + UnifiedCredentials credentials = + UnifiedCredentials.builder().setKeyId("foo").setKeySecret(null).setProjectId("foo").build(); + ConversationContext context = ConversationContext.builder().build(); + ServerConfiguration server = new ServerConfiguration("foo"); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new TemplatesService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("keySecret")); + } + + @Test + void doNotAcceptNullProject() { + UnifiedCredentials credentials = + UnifiedCredentials.builder().setKeyId("foo").setKeySecret("foo").setProjectId(null).build(); + ConversationContext context = ConversationContext.builder().build(); + ServerConfiguration server = new ServerConfiguration("foo"); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new TemplatesService(credentials, context, server, httpClient)); + assertTrue(exception.getMessage().contains("projectId")); + } + + @Test + void doNotAcceptNullCredentials() { + + ConversationContext context = ConversationContext.builder().build(); + ServerConfiguration server = new ServerConfiguration("foo"); + Exception exception = + assertThrows( + NullPointerException.class, + () -> new TemplatesService(null, context, server, httpClient)); + assertTrue( + exception.getMessage().contains("Templates service requires credentials to be defined")); + } + + @Test + void doNotAcceptNullContext() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ServerConfiguration server = new ServerConfiguration("foo"); + Exception exception = + assertThrows( + NullPointerException.class, + () -> new TemplatesService(credentials, null, server, httpClient)); + assertTrue(exception.getMessage().contains("Templates service requires context to be defined")); + } + + @Test + void doNotAcceptEmptyManagementURL() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ConversationContext context = + ConversationContext.builder().setTemplateManagementUrl("").build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new TemplatesService(credentials, context, server, httpClient)); + assertTrue( + exception + .getMessage() + .contains("Templates service requires 'templateManagementUrl' to be defined")); + } + + @Test + void doNotAcceptNullManagementURL() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ConversationContext context = ConversationContext.builder().build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new TemplatesService(credentials, context, server, httpClient)); + assertTrue( + exception + .getMessage() + .contains("Templates service requires 'templateManagementUrl' to be defined")); + } + + @Test + void passInit() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ConversationContext context = + ConversationContext.builder().setTemplateManagementUrl("foo").build(); + ServerConfiguration server = new ServerConfiguration("foo"); + assertDoesNotThrow( + () -> new TemplatesService(credentials, context, server, httpClient), "Init passed"); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/v1/TemplatesServiceV1Test.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/v1/TemplatesServiceV1Test.java new file mode 100644 index 00000000..82b01604 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/v1/TemplatesServiceV1Test.java @@ -0,0 +1,113 @@ +package com.sinch.sdk.domains.conversation.api.templates.adapters.v1; + +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.TestWithResources; +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.conversation.api.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.v1.TemplateV1DtoTest; +import com.sinch.sdk.domains.conversation.models.templates.v1.internal.V1ListTemplatesResponseInternalDtoTest; +import com.sinch.sdk.domains.conversation.templates.api.internal.TemplatesV1Api; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import com.sinch.sdk.models.ConversationContext; +import java.util.Collection; +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 +public class TemplatesServiceV1Test extends TemplatesBaseTest { + + @Mock ConversationContext context; + @Mock TemplatesV1Api api; + @Mock HttpClient httpClient; + @Mock Map authManagers; + @Captor ArgumentCaptor uriPartIDCaptor; + @Captor ArgumentCaptor idCaptor; + + TemplatesServiceV1 service; + String uriPartID = "foovalue"; + + @BeforeEach + public void initMocks() { + service = spy(new TemplatesServiceV1(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @Test + void create() throws ApiException { + + when(api.templatesCreateTemplate(eq(uriPartID), eq(TemplateV1DtoTest.expectedDto))) + .thenReturn(TemplateV1DtoTest.expectedDto); + + TemplateV1 response = service.create(TemplateV1DtoTest.expectedDto); + + TestHelpers.recursiveEquals(response, TemplateV1DtoTest.expectedDto); + } + + @Test + void get() throws ApiException { + + when(api.templatesGetTemplate(eq(uriPartID), eq(TemplateV1DtoTest.expectedDto.getId()))) + .thenReturn(TemplateV1DtoTest.expectedDto); + + TemplateV1 response = service.get(TemplateV1DtoTest.expectedDto.getId()); + + TestHelpers.recursiveEquals(response, TemplateV1DtoTest.expectedDto); + } + + @Test + void list() throws ApiException { + + when(api.templatesListTemplates(eq(uriPartID))) + .thenReturn(V1ListTemplatesResponseInternalDtoTest.expectedDto); + + Collection response = service.list(); + + Iterator iterator = response.iterator(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TemplateV1 item = iterator.next(); + TestHelpers.recursiveEquals( + item, V1ListTemplatesResponseInternalDtoTest.expectedDto.getTemplates().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + } + + @Test + void update() throws ApiException { + + when(api.templatesUpdateTemplate( + eq(uriPartID), + eq(TemplateV1DtoTest.expectedDto.getId()), + eq(TemplateV1DtoTest.expectedDto), + eq(null))) + .thenReturn(TemplateV1DtoTest.expectedDto); + + TemplateV1 response = + service.update(TemplateV1DtoTest.expectedDto.getId(), TemplateV1DtoTest.expectedDto); + + TestHelpers.recursiveEquals(response, TemplateV1DtoTest.expectedDto); + } + + @Test + void delete() throws ApiException { + + service.delete(TemplateV1DtoTest.expectedDto.getId()); + + verify(api).templatesDeleteTemplate(uriPartIDCaptor.capture(), idCaptor.capture()); + + Assertions.assertThat(uriPartIDCaptor.getValue()).isEqualTo(uriPartID); + Assertions.assertThat(idCaptor.getValue()).isEqualTo(TemplateV1DtoTest.expectedDto.getId()); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/v2/TemplatesServiceV2Test.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/v2/TemplatesServiceV2Test.java new file mode 100644 index 00000000..0c936e36 --- /dev/null +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/v2/TemplatesServiceV2Test.java @@ -0,0 +1,141 @@ +package com.sinch.sdk.domains.conversation.api.templates.adapters.v2; + +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.TestWithResources; +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.conversation.api.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.v2.TemplateV2DtoTest; +import com.sinch.sdk.domains.conversation.models.templates.v2.internal.V2ListTemplatesResponseInternalDtoTest; +import com.sinch.sdk.domains.conversation.models.templates.v2.internal.V2ListTranslationsResponseInternalDtoTest; +import com.sinch.sdk.domains.conversation.templates.api.internal.TemplatesV2Api; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import com.sinch.sdk.domains.conversation.templates.models.v2.request.TranslationListRequest; +import com.sinch.sdk.models.ConversationContext; +import java.util.Collection; +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 +public class TemplatesServiceV2Test extends TemplatesBaseTest { + + @Mock ConversationContext context; + @Mock TemplatesV2Api api; + @Mock HttpClient httpClient; + @Mock Map authManagers; + @Captor ArgumentCaptor uriPartIDCaptor; + @Captor ArgumentCaptor idCaptor; + + TemplatesServiceV2 service; + String uriPartID = "foovalue"; + + @BeforeEach + public void initMocks() { + service = spy(new TemplatesServiceV2(uriPartID, context, httpClient, authManagers)); + doReturn(api).when(service).getApi(); + } + + @Test + void create() throws ApiException { + + when(api.templatesV2CreateTemplate(eq(uriPartID), eq(TemplateV2DtoTest.expectedDto))) + .thenReturn(TemplateV2DtoTest.expectedDto); + + TemplateV2 response = service.create(TemplateV2DtoTest.expectedDto); + + TestHelpers.recursiveEquals(response, TemplateV2DtoTest.expectedDto); + } + + @Test + void get() throws ApiException { + + when(api.templatesV2GetTemplate(eq(uriPartID), eq(TemplateV2DtoTest.expectedDto.getId()))) + .thenReturn(TemplateV2DtoTest.expectedDto); + + TemplateV2 response = service.get(TemplateV2DtoTest.expectedDto.getId()); + + TestHelpers.recursiveEquals(response, TemplateV2DtoTest.expectedDto); + } + + @Test + void list() throws ApiException { + + when(api.templatesV2ListTemplates(eq(uriPartID))) + .thenReturn(V2ListTemplatesResponseInternalDtoTest.expectedDto); + + Collection response = service.list(); + + Iterator iterator = response.iterator(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TemplateV2 item = iterator.next(); + TestHelpers.recursiveEquals( + item, V2ListTemplatesResponseInternalDtoTest.expectedDto.getTemplates().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + } + + @Test + void listTranslations() throws ApiException { + + when(api.templatesV2ListTranslations( + eq(uriPartID), + eq(TemplateV2DtoTest.expectedDto.getId()), + eq("language code"), + eq("translation version"))) + .thenReturn(V2ListTranslationsResponseInternalDtoTest.expectedDto); + + Collection response = + service.listTranslations( + TemplateV2DtoTest.expectedDto.getId(), + TranslationListRequest.builder() + .setLanguageCode("language code") + .setTranslationVersion("translation version") + .build()); + + Iterator iterator = response.iterator(); + Assertions.assertThat(iterator.hasNext()).isEqualTo(true); + TemplateTranslation item = iterator.next(); + TestHelpers.recursiveEquals( + item, V2ListTranslationsResponseInternalDtoTest.expectedDto.getTranslations().get(0)); + Assertions.assertThat(iterator.hasNext()).isEqualTo(false); + } + + @Test + void update() throws ApiException { + + when(api.templatesV2UpdateTemplate( + eq(uriPartID), + eq(TemplateV2DtoTest.expectedDto.getId()), + eq(TemplateV2DtoTest.expectedDto))) + .thenReturn(TemplateV2DtoTest.expectedDto); + + TemplateV2 response = + service.update(TemplateV2DtoTest.expectedDto.getId(), TemplateV2DtoTest.expectedDto); + + TestHelpers.recursiveEquals(response, TemplateV2DtoTest.expectedDto); + } + + @Test + void delete() throws ApiException { + + service.delete(TemplateV2DtoTest.expectedDto.getId()); + + verify(api).templatesV2DeleteTemplate(uriPartIDCaptor.capture(), idCaptor.capture()); + + Assertions.assertThat(uriPartIDCaptor.getValue()).isEqualTo(uriPartID); + Assertions.assertThat(idCaptor.getValue()).isEqualTo(TemplateV2DtoTest.expectedDto.getId()); + } +} diff --git a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationServiceTest.java b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationServiceTest.java index 045124ae..1d63dcab 100644 --- a/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationServiceTest.java +++ b/client/src/test/java/com/sinch/sdk/domains/conversation/api/v1/adapters/ConversationServiceTest.java @@ -1,5 +1,6 @@ package com.sinch.sdk.domains.conversation.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; @@ -83,4 +84,54 @@ void doNotAcceptNullContext() { assertTrue( exception.getMessage().contains("Conversation service requires context to be defined")); } + + @Test + void doNotAcceptEmptyURL() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ConversationContext context = ConversationContext.builder().setUrl("").build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new ConversationService(credentials, context, server, httpClient)); + assertTrue( + exception.getMessage().contains("Conversation service requires 'url' to be defined")); + } + + @Test + void doNotAcceptNullURL() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ConversationContext context = ConversationContext.builder().build(); + ServerConfiguration server = new ServerConfiguration(""); + Exception exception = + assertThrows( + IllegalArgumentException.class, + () -> new ConversationService(credentials, context, server, httpClient)); + assertTrue( + exception.getMessage().contains("Conversation service requires 'url' to be defined")); + } + + @Test + void passInit() { + UnifiedCredentials credentials = + UnifiedCredentials.builder() + .setKeyId("foo") + .setKeySecret("foo") + .setProjectId("foo") + .build(); + ConversationContext context = ConversationContext.builder().setUrl("foo").build(); + ServerConfiguration server = new ServerConfiguration("foo"); + assertDoesNotThrow( + () -> new ConversationService(credentials, context, server, httpClient), "Init passed"); + } } diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/api/internal/TemplatesV1Api.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/api/internal/TemplatesV1Api.java new file mode 100644 index 00000000..ea61eeb4 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/api/internal/TemplatesV1Api.java @@ -0,0 +1,460 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.api.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.conversation.templates.models.v1.TemplateV1; +import com.sinch.sdk.domains.conversation.templates.models.v1.internal.V1ListTemplatesResponseInternal; +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 TemplatesV1Api { + + private static final Logger LOGGER = Logger.getLogger(TemplatesV1Api.class.getName()); + private HttpClient httpClient; + private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; + private HttpMapper mapper; + + public TemplatesV1Api( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + } + + /** + * Creates a template + * + * @param projectId Required. The project ID. (required) + * @param templateV1 Required. The template to create. (required) + * @return TemplateV1 + * @throws ApiException if fails to make API call + */ + public TemplateV1 templatesCreateTemplate(String projectId, TemplateV1 templateV1) + throws ApiException { + + LOGGER.finest( + "[templatesCreateTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateV1: " + + templateV1); + + HttpRequest httpRequest = templatesCreateTemplateRequestBuilder(projectId, templateV1); + 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 templatesCreateTemplateRequestBuilder(String projectId, TemplateV1 templateV1) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesCreateTemplate"); + } + // verify the required parameter 'templateV1' is set + if (templateV1 == null) { + throw new ApiException( + 400, "Missing the required parameter 'templateV1' when calling templatesCreateTemplate"); + } + + String localVarPath = + "/v1/projects/{project_id}/templates" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.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("Basic", "oAuth2"); + final String serializedBody = mapper.serialize(localVarContentTypes, templateV1); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Delete a template. + * + * @param projectId Required. The project ID. (required) + * @param templateId Required. The ID of the template to fetch. (required) + * @return Object + * @throws ApiException if fails to make API call + */ + public Object templatesDeleteTemplate(String projectId, String templateId) throws ApiException { + + LOGGER.finest( + "[templatesDeleteTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId); + + HttpRequest httpRequest = templatesDeleteTemplateRequestBuilder(projectId, templateId); + 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 templatesDeleteTemplateRequestBuilder(String projectId, String templateId) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesDeleteTemplate"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, "Missing the required parameter 'templateId' when calling templatesDeleteTemplate"); + } + + String localVarPath = + "/v1/projects/{project_id}/templates/{template_id}" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.DELETE, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Get a template + * + * @param projectId Required. The project ID. (required) + * @param templateId Required. The ID of the template to fetch. (required) + * @return TemplateV1 + * @throws ApiException if fails to make API call + */ + public TemplateV1 templatesGetTemplate(String projectId, String templateId) throws ApiException { + + LOGGER.finest( + "[templatesGetTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId); + + HttpRequest httpRequest = templatesGetTemplateRequestBuilder(projectId, templateId); + 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 templatesGetTemplateRequestBuilder(String projectId, String templateId) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesGetTemplate"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, "Missing the required parameter 'templateId' when calling templatesGetTemplate"); + } + + String localVarPath = + "/v1/projects/{project_id}/templates/{template_id}" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * List all templates belonging to a project ID. + * + * @param projectId Required. The project ID. (required) + * @return V1ListTemplatesResponseInternal + * @throws ApiException if fails to make API call + */ + public V1ListTemplatesResponseInternal templatesListTemplates(String projectId) + throws ApiException { + + LOGGER.finest("[templatesListTemplates]" + " " + "projectId: " + projectId); + + HttpRequest httpRequest = templatesListTemplatesRequestBuilder(projectId); + 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 templatesListTemplatesRequestBuilder(String projectId) throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesListTemplates"); + } + + String localVarPath = + "/v1/projects/{project_id}/templates" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Updates a template. + * + * @param projectId Required. The project ID. (required) + * @param templateId The id of the template to be updated. Specified or automatically generated + * during template creation. Unique per project. (required) + * @param templateV1 Required. The updated template. (required) + * @param updateMask The set of field mask paths. (optional + * @return TemplateV1 + * @throws ApiException if fails to make API call + */ + public TemplateV1 templatesUpdateTemplate( + String projectId, String templateId, TemplateV1 templateV1, List updateMask) + throws ApiException { + + LOGGER.finest( + "[templatesUpdateTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId + + ", " + + "templateV1: " + + templateV1 + + ", " + + "updateMask: " + + updateMask); + + HttpRequest httpRequest = + templatesUpdateTemplateRequestBuilder(projectId, templateId, templateV1, updateMask); + 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 templatesUpdateTemplateRequestBuilder( + String projectId, String templateId, TemplateV1 templateV1, List updateMask) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesUpdateTemplate"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, "Missing the required parameter 'templateId' when calling templatesUpdateTemplate"); + } + // verify the required parameter 'templateV1' is set + if (templateV1 == null) { + throw new ApiException( + 400, "Missing the required parameter 'templateV1' when calling templatesUpdateTemplate"); + } + + String localVarPath = + "/v1/projects/{project_id}/templates/{template_id}" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != updateMask) { + localVarQueryParams.add( + new URLParameter( + "update_mask", updateMask, 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("Basic", "oAuth2"); + final String serializedBody = mapper.serialize(localVarContentTypes, templateV1); + + return new HttpRequest( + localVarPath, + HttpMethod.PATCH, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/api/internal/TemplatesV2Api.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/api/internal/TemplatesV2Api.java new file mode 100644 index 00000000..20b1d1b0 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/api/internal/TemplatesV2Api.java @@ -0,0 +1,567 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.api.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.conversation.templates.models.v2.TemplateV2; +import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTemplatesResponseInternal; +import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTranslationsResponseInternal; +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 TemplatesV2Api { + + private static final Logger LOGGER = Logger.getLogger(TemplatesV2Api.class.getName()); + private HttpClient httpClient; + private ServerConfiguration serverConfiguration; + private Map authManagersByOasSecuritySchemes; + private HttpMapper mapper; + + public TemplatesV2Api( + HttpClient httpClient, + ServerConfiguration serverConfiguration, + Map authManagersByOasSecuritySchemes, + HttpMapper mapper) { + this.httpClient = httpClient; + this.serverConfiguration = serverConfiguration; + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; + this.mapper = mapper; + } + + /** + * Creates a template + * + * @param projectId Required. The project ID. (required) + * @param templateV2 Required. The template to create. (required) + * @return TemplateV2 + * @throws ApiException if fails to make API call + */ + public TemplateV2 templatesV2CreateTemplate(String projectId, TemplateV2 templateV2) + throws ApiException { + + LOGGER.finest( + "[templatesV2CreateTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateV2: " + + templateV2); + + HttpRequest httpRequest = templatesV2CreateTemplateRequestBuilder(projectId, templateV2); + 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 templatesV2CreateTemplateRequestBuilder( + String projectId, TemplateV2 templateV2) throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesV2CreateTemplate"); + } + // verify the required parameter 'templateV2' is set + if (templateV2 == null) { + throw new ApiException( + 400, + "Missing the required parameter 'templateV2' when calling templatesV2CreateTemplate"); + } + + String localVarPath = + "/v2/projects/{project_id}/templates" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.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("Basic", "oAuth2"); + final String serializedBody = mapper.serialize(localVarContentTypes, templateV2); + + return new HttpRequest( + localVarPath, + HttpMethod.POST, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Delete a template. + * + * @param projectId Required. The project ID. (required) + * @param templateId Required. The ID of the template to delete. (required) + * @return Object + * @throws ApiException if fails to make API call + */ + public Object templatesV2DeleteTemplate(String projectId, String templateId) throws ApiException { + + LOGGER.finest( + "[templatesV2DeleteTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId); + + HttpRequest httpRequest = templatesV2DeleteTemplateRequestBuilder(projectId, templateId); + 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 templatesV2DeleteTemplateRequestBuilder(String projectId, String templateId) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesV2DeleteTemplate"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, + "Missing the required parameter 'templateId' when calling templatesV2DeleteTemplate"); + } + + String localVarPath = + "/v2/projects/{project_id}/templates/{template_id}" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.DELETE, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Get a template + * + * @param projectId Required. The project ID. (required) + * @param templateId Required. The ID of the template to fetch. (required) + * @return TemplateV2 + * @throws ApiException if fails to make API call + */ + public TemplateV2 templatesV2GetTemplate(String projectId, String templateId) + throws ApiException { + + LOGGER.finest( + "[templatesV2GetTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId); + + HttpRequest httpRequest = templatesV2GetTemplateRequestBuilder(projectId, templateId); + 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 templatesV2GetTemplateRequestBuilder(String projectId, String templateId) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesV2GetTemplate"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, "Missing the required parameter 'templateId' when calling templatesV2GetTemplate"); + } + + String localVarPath = + "/v2/projects/{project_id}/templates/{template_id}" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * List all templates belonging to a project ID. + * + * @param projectId Required. The project ID. (required) + * @return V2ListTemplatesResponseInternal + * @throws ApiException if fails to make API call + */ + public V2ListTemplatesResponseInternal templatesV2ListTemplates(String projectId) + throws ApiException { + + LOGGER.finest("[templatesV2ListTemplates]" + " " + "projectId: " + projectId); + + HttpRequest httpRequest = templatesV2ListTemplatesRequestBuilder(projectId); + 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 templatesV2ListTemplatesRequestBuilder(String projectId) throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesV2ListTemplates"); + } + + String localVarPath = + "/v2/projects/{project_id}/templates" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * List translations for a template + * + * @param projectId Required. The project ID. (required) + * @param templateId Required. The ID of the template to fetch. (required) + * @param languageCode Optional. The translation's language code. (optional) + * @param translationVersion Optional. The translation's version. (optional) + * @return V2ListTranslationsResponseInternal + * @throws ApiException if fails to make API call + */ + public V2ListTranslationsResponseInternal templatesV2ListTranslations( + String projectId, String templateId, String languageCode, String translationVersion) + throws ApiException { + + LOGGER.finest( + "[templatesV2ListTranslations]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId + + ", " + + "languageCode: " + + languageCode + + ", " + + "translationVersion: " + + translationVersion); + + HttpRequest httpRequest = + templatesV2ListTranslationsRequestBuilder( + projectId, templateId, languageCode, translationVersion); + 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 templatesV2ListTranslationsRequestBuilder( + String projectId, String templateId, String languageCode, String translationVersion) + throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, + "Missing the required parameter 'projectId' when calling templatesV2ListTranslations"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, + "Missing the required parameter 'templateId' when calling templatesV2ListTranslations"); + } + + String localVarPath = + "/v2/projects/{project_id}/templates/{template_id}/translations" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.toString())); + + List localVarQueryParams = new ArrayList<>(); + if (null != languageCode) { + localVarQueryParams.add( + new URLParameter( + "language_code", + languageCode, + URLParameter.STYLE.valueOf("form".toUpperCase()), + true)); + } + if (null != translationVersion) { + localVarQueryParams.add( + new URLParameter( + "translation_version", + translationVersion, + 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("Basic", "oAuth2"); + final String serializedBody = null; + + return new HttpRequest( + localVarPath, + HttpMethod.GET, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } + + /** + * Updates a template. + * + * @param projectId Required. The project ID. (required) + * @param templateId The id of the template to be updated. Specified or automatically generated + * during template creation. Unique per project. (required) + * @param templateV2 Required. The updated template. (required) + * @return TemplateV2 + * @throws ApiException if fails to make API call + */ + public TemplateV2 templatesV2UpdateTemplate( + String projectId, String templateId, TemplateV2 templateV2) throws ApiException { + + LOGGER.finest( + "[templatesV2UpdateTemplate]" + + " " + + "projectId: " + + projectId + + ", " + + "templateId: " + + templateId + + ", " + + "templateV2: " + + templateV2); + + HttpRequest httpRequest = + templatesV2UpdateTemplateRequestBuilder(projectId, templateId, templateV2); + 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 templatesV2UpdateTemplateRequestBuilder( + String projectId, String templateId, TemplateV2 templateV2) throws ApiException { + // verify the required parameter 'projectId' is set + if (projectId == null) { + throw new ApiException( + 400, "Missing the required parameter 'projectId' when calling templatesV2UpdateTemplate"); + } + // verify the required parameter 'templateId' is set + if (templateId == null) { + throw new ApiException( + 400, + "Missing the required parameter 'templateId' when calling templatesV2UpdateTemplate"); + } + // verify the required parameter 'templateV2' is set + if (templateV2 == null) { + throw new ApiException( + 400, + "Missing the required parameter 'templateV2' when calling templatesV2UpdateTemplate"); + } + + String localVarPath = + "/v2/projects/{project_id}/templates/{template_id}" + .replaceAll( + "\\{" + "project_id" + "\\}", URLPathUtils.encodePathSegment(projectId.toString())) + .replaceAll( + "\\{" + "template_id" + "\\}", + URLPathUtils.encodePathSegment(templateId.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("Basic", "oAuth2"); + final String serializedBody = mapper.serialize(localVarContentTypes, templateV2); + + return new HttpRequest( + localVarPath, + HttpMethod.PUT, + localVarQueryParams, + serializedBody, + localVarHeaderParams, + localVarAccepts, + localVarContentTypes, + localVarAuthNames); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/TemplateVariable.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/TemplateVariable.java new file mode 100644 index 00000000..b954322e --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/TemplateVariable.java @@ -0,0 +1,70 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** TemplateVariable */ +@JsonDeserialize(builder = TemplateVariableImpl.Builder.class) +public interface TemplateVariable { + + /** + * Get key + * + * @return key + */ + String getKey(); + + /** + * Get previewValue + * + * @return previewValue + */ + String getPreviewValue(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new TemplateVariableImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param key see getter + * @return Current builder + * @see #getKey + */ + Builder setKey(String key); + + /** + * see getter + * + * @param previewValue see getter + * @return Current builder + * @see #getPreviewValue + */ + Builder setPreviewValue(String previewValue); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TemplateVariable build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/TemplateVariableImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/TemplateVariableImpl.java new file mode 100644 index 00000000..2d5b22b1 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/TemplateVariableImpl.java @@ -0,0 +1,118 @@ +package com.sinch.sdk.domains.conversation.templates.models; + +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({ + TemplateVariableImpl.JSON_PROPERTY_KEY, + TemplateVariableImpl.JSON_PROPERTY_PREVIEW_VALUE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TemplateVariableImpl implements TemplateVariable { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_KEY = "key"; + + private OptionalValue key; + + public static final String JSON_PROPERTY_PREVIEW_VALUE = "preview_value"; + + private OptionalValue previewValue; + + public TemplateVariableImpl() {} + + protected TemplateVariableImpl(OptionalValue key, OptionalValue previewValue) { + this.key = key; + this.previewValue = previewValue; + } + + @JsonIgnore + public String getKey() { + return key.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_KEY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue key() { + return key; + } + + @JsonIgnore + public String getPreviewValue() { + return previewValue.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PREVIEW_VALUE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue previewValue() { + return previewValue; + } + + /** Return true if this typeTemplateVariable object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TemplateVariableImpl typeTemplateVariable = (TemplateVariableImpl) o; + return Objects.equals(this.key, typeTemplateVariable.key) + && Objects.equals(this.previewValue, typeTemplateVariable.previewValue); + } + + @Override + public int hashCode() { + return Objects.hash(key, previewValue); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TemplateVariableImpl {\n"); + sb.append(" key: ").append(toIndentedString(key)).append("\n"); + sb.append(" previewValue: ").append(toIndentedString(previewValue)).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 TemplateVariable.Builder { + OptionalValue key = OptionalValue.empty(); + OptionalValue previewValue = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_KEY) + public Builder setKey(String key) { + this.key = OptionalValue.of(key); + return this; + } + + @JsonProperty(JSON_PROPERTY_PREVIEW_VALUE) + public Builder setPreviewValue(String previewValue) { + this.previewValue = OptionalValue.of(previewValue); + return this; + } + + public TemplateVariable build() { + return new TemplateVariableImpl(key, previewValue); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateChannel.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateChannel.java new file mode 100644 index 00000000..34e71e46 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateChannel.java @@ -0,0 +1,68 @@ +package com.sinch.sdk.domains.conversation.templates.models.v1; + +import com.sinch.sdk.core.utils.EnumDynamic; +import com.sinch.sdk.core.utils.EnumSupportDynamic; +import java.util.Arrays; +import java.util.stream.Stream; + +/** Gets or Sets typeChannel */ +public class TemplateChannel extends EnumDynamic { + + public static final TemplateChannel UNSPECIFIED = new TemplateChannel("UNSPECIFIED"); + + public static final TemplateChannel CONVERSATION = new TemplateChannel("CONVERSATION"); + + public static final TemplateChannel MESSENGER = new TemplateChannel("MESSENGER"); + + public static final TemplateChannel WHATSAPP = new TemplateChannel("WHATSAPP"); + + public static final TemplateChannel RCS = new TemplateChannel("RCS"); + + public static final TemplateChannel SMS = new TemplateChannel("SMS"); + + public static final TemplateChannel VIBER = new TemplateChannel("VIBER"); + + public static final TemplateChannel VIBERBM = new TemplateChannel("VIBERBM"); + + public static final TemplateChannel TELEGRAM = new TemplateChannel("TELEGRAM"); + + public static final TemplateChannel INSTAGRAM = new TemplateChannel("INSTAGRAM"); + + public static final TemplateChannel KAKAOTALK = new TemplateChannel("KAKAOTALK"); + + public static final TemplateChannel APPLEBC = new TemplateChannel("APPLEBC"); + + private static final EnumSupportDynamic ENUM_SUPPORT = + new EnumSupportDynamic<>( + TemplateChannel.class, + TemplateChannel::new, + Arrays.asList( + UNSPECIFIED, + CONVERSATION, + MESSENGER, + WHATSAPP, + RCS, + SMS, + VIBER, + VIBERBM, + TELEGRAM, + INSTAGRAM, + KAKAOTALK, + APPLEBC)); + + private TemplateChannel(String value) { + super(value); + } + + public static Stream values() { + return ENUM_SUPPORT.values(); + } + + public static TemplateChannel from(String value) { + return ENUM_SUPPORT.from(value); + } + + public static String valueOf(TemplateChannel e) { + return ENUM_SUPPORT.valueOf(e); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateTranslation.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateTranslation.java new file mode 100644 index 00000000..8bc621ba --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateTranslation.java @@ -0,0 +1,138 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v1; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import java.time.Instant; +import java.util.List; + +/** TemplateTranslation */ +@JsonDeserialize(builder = TemplateTranslationImpl.Builder.class) +public interface TemplateTranslation { + + /** + * This is the definition of the template with the language specified in the language_code field. + * + * @return content + */ + String getContent(); + + /** + * Timestamp when the translation was created. + * + * @return createTime + */ + Instant getCreateTime(); + + /** + * The BCP-47 language code, such as en-US or sr-Latn. For more + * information, see https://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + * + * @return languageCode + */ + String getLanguageCode(); + + /** + * Timestamp of when the translation was updated. + * + * @return updateTime + */ + Instant getUpdateTime(); + + /** + * List of expected variables. Can be used for request validation. + * + * @return variables + */ + List getVariables(); + + /** + * The version of template. + * + * @return version + */ + String getVersion(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new TemplateTranslationImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param content see getter + * @return Current builder + * @see #getContent + */ + Builder setContent(String content); + + /** + * see getter + * + * @param createTime see getter + * @return Current builder + * @see #getCreateTime + */ + Builder setCreateTime(Instant createTime); + + /** + * see getter + * + * @param languageCode see getter + * @return Current builder + * @see #getLanguageCode + */ + Builder setLanguageCode(String languageCode); + + /** + * see getter + * + * @param updateTime see getter + * @return Current builder + * @see #getUpdateTime + */ + Builder setUpdateTime(Instant updateTime); + + /** + * see getter + * + * @param variables see getter + * @return Current builder + * @see #getVariables + */ + Builder setVariables(List variables); + + /** + * see getter + * + * @param version see getter + * @return Current builder + * @see #getVersion + */ + Builder setVersion(String version); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TemplateTranslation build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateTranslationImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateTranslationImpl.java new file mode 100644 index 00000000..a14b1016 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateTranslationImpl.java @@ -0,0 +1,232 @@ +package com.sinch.sdk.domains.conversation.templates.models.v1; + +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.conversation.templates.models.TemplateVariable; +import java.time.Instant; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({ + TemplateTranslationImpl.JSON_PROPERTY_CONTENT, + TemplateTranslationImpl.JSON_PROPERTY_CREATE_TIME, + TemplateTranslationImpl.JSON_PROPERTY_LANGUAGE_CODE, + TemplateTranslationImpl.JSON_PROPERTY_UPDATE_TIME, + TemplateTranslationImpl.JSON_PROPERTY_VARIABLES, + TemplateTranslationImpl.JSON_PROPERTY_VERSION +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TemplateTranslationImpl implements TemplateTranslation { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_CONTENT = "content"; + + private OptionalValue content; + + public static final String JSON_PROPERTY_CREATE_TIME = "create_time"; + + private OptionalValue createTime; + + public static final String JSON_PROPERTY_LANGUAGE_CODE = "language_code"; + + private OptionalValue languageCode; + + public static final String JSON_PROPERTY_UPDATE_TIME = "update_time"; + + private OptionalValue updateTime; + + public static final String JSON_PROPERTY_VARIABLES = "variables"; + + private OptionalValue> variables; + + public static final String JSON_PROPERTY_VERSION = "version"; + + private OptionalValue version; + + public TemplateTranslationImpl() {} + + protected TemplateTranslationImpl( + OptionalValue content, + OptionalValue createTime, + OptionalValue languageCode, + OptionalValue updateTime, + OptionalValue> variables, + OptionalValue version) { + this.content = content; + this.createTime = createTime; + this.languageCode = languageCode; + this.updateTime = updateTime; + this.variables = variables; + this.version = version; + } + + @JsonIgnore + public String getContent() { + return content.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CONTENT) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue content() { + return content; + } + + @JsonIgnore + public Instant getCreateTime() { + return createTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue createTime() { + return createTime; + } + + @JsonIgnore + public String getLanguageCode() { + return languageCode.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_LANGUAGE_CODE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue languageCode() { + return languageCode; + } + + @JsonIgnore + public Instant getUpdateTime() { + return updateTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue updateTime() { + return updateTime; + } + + @JsonIgnore + public List getVariables() { + return variables.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_VARIABLES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> variables() { + return variables; + } + + @JsonIgnore + public String getVersion() { + return version.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_VERSION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue version() { + return version; + } + + /** Return true if this typeTemplateTranslation object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TemplateTranslationImpl typeTemplateTranslation = (TemplateTranslationImpl) o; + return Objects.equals(this.content, typeTemplateTranslation.content) + && Objects.equals(this.createTime, typeTemplateTranslation.createTime) + && Objects.equals(this.languageCode, typeTemplateTranslation.languageCode) + && Objects.equals(this.updateTime, typeTemplateTranslation.updateTime) + && Objects.equals(this.variables, typeTemplateTranslation.variables) + && Objects.equals(this.version, typeTemplateTranslation.version); + } + + @Override + public int hashCode() { + return Objects.hash(content, createTime, languageCode, updateTime, variables, version); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TemplateTranslationImpl {\n"); + sb.append(" content: ").append(toIndentedString(content)).append("\n"); + sb.append(" createTime: ").append(toIndentedString(createTime)).append("\n"); + sb.append(" languageCode: ").append(toIndentedString(languageCode)).append("\n"); + sb.append(" updateTime: ").append(toIndentedString(updateTime)).append("\n"); + sb.append(" variables: ").append(toIndentedString(variables)).append("\n"); + sb.append(" version: ").append(toIndentedString(version)).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 TemplateTranslation.Builder { + OptionalValue content = OptionalValue.empty(); + OptionalValue createTime = OptionalValue.empty(); + OptionalValue languageCode = OptionalValue.empty(); + OptionalValue updateTime = OptionalValue.empty(); + OptionalValue> variables = OptionalValue.empty(); + OptionalValue version = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_CONTENT) + public Builder setContent(String content) { + this.content = OptionalValue.of(content); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + public Builder setCreateTime(Instant createTime) { + this.createTime = OptionalValue.of(createTime); + return this; + } + + @JsonProperty(JSON_PROPERTY_LANGUAGE_CODE) + public Builder setLanguageCode(String languageCode) { + this.languageCode = OptionalValue.of(languageCode); + return this; + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + public Builder setUpdateTime(Instant updateTime) { + this.updateTime = OptionalValue.of(updateTime); + return this; + } + + @JsonProperty(JSON_PROPERTY_VARIABLES) + public Builder setVariables(List variables) { + this.variables = OptionalValue.of(variables); + return this; + } + + @JsonProperty(JSON_PROPERTY_VERSION) + public Builder setVersion(String version) { + this.version = OptionalValue.of(version); + return this; + } + + public TemplateTranslation build() { + return new TemplateTranslationImpl( + content, createTime, languageCode, updateTime, variables, version); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateV1.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateV1.java new file mode 100644 index 00000000..b1b80c99 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateV1.java @@ -0,0 +1,154 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v1; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.Instant; +import java.util.List; + +/** TemplateV1 */ +@JsonDeserialize(builder = TemplateV1Impl.Builder.class) +public interface TemplateV1 { + + /** + * Get channel + * + * @return channel + */ + TemplateChannel getChannel(); + + /** + * Timestamp when the template was created. + * + * @return createTime + */ + Instant getCreateTime(); + + /** + * The default translation to use if not specified. Specified as a BCP-47 language_code + * and the language_code must exist in the translations list. + * + * @return defaultTranslation + */ + String getDefaultTranslation(); + + /** + * The description of the template. + * + * @return description + */ + String getDescription(); + + /** + * The id of the template. Specify this yourself during creation otherwise we will generate an ID + * for you. This has to be unique for a given project. + * + * @return id + */ + String getId(); + + /** + * List of translations for the template. + * + * @return translations + */ + List getTranslations(); + + /** + * Timestamp when the template was updated. + * + * @return updateTime + */ + Instant getUpdateTime(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new TemplateV1Impl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param channel see getter + * @return Current builder + * @see #getChannel + */ + Builder setChannel(TemplateChannel channel); + + /** + * see getter + * + * @param createTime see getter + * @return Current builder + * @see #getCreateTime + */ + Builder setCreateTime(Instant createTime); + + /** + * see getter + * + * @param defaultTranslation see getter + * @return Current builder + * @see #getDefaultTranslation + */ + Builder setDefaultTranslation(String defaultTranslation); + + /** + * see getter + * + * @param description see getter + * @return Current builder + * @see #getDescription + */ + Builder setDescription(String description); + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + */ + Builder setId(String id); + + /** + * see getter + * + * @param translations see getter + * @return Current builder + * @see #getTranslations + */ + Builder setTranslations(List translations); + + /** + * see getter + * + * @param updateTime see getter + * @return Current builder + * @see #getUpdateTime + */ + Builder setUpdateTime(Instant updateTime); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TemplateV1 build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateV1Impl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateV1Impl.java new file mode 100644 index 00000000..2429a691 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/TemplateV1Impl.java @@ -0,0 +1,259 @@ +package com.sinch.sdk.domains.conversation.templates.models.v1; + +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.List; +import java.util.Objects; + +@JsonPropertyOrder({ + TemplateV1Impl.JSON_PROPERTY_CHANNEL, + TemplateV1Impl.JSON_PROPERTY_CREATE_TIME, + TemplateV1Impl.JSON_PROPERTY_DEFAULT_TRANSLATION, + TemplateV1Impl.JSON_PROPERTY_DESCRIPTION, + TemplateV1Impl.JSON_PROPERTY_ID, + TemplateV1Impl.JSON_PROPERTY_TRANSLATIONS, + TemplateV1Impl.JSON_PROPERTY_UPDATE_TIME +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TemplateV1Impl implements TemplateV1 { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_CHANNEL = "channel"; + + private OptionalValue channel; + + public static final String JSON_PROPERTY_CREATE_TIME = "create_time"; + + private OptionalValue createTime; + + public static final String JSON_PROPERTY_DEFAULT_TRANSLATION = "default_translation"; + + private OptionalValue defaultTranslation; + + public static final String JSON_PROPERTY_DESCRIPTION = "description"; + + private OptionalValue description; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_TRANSLATIONS = "translations"; + + private OptionalValue> translations; + + public static final String JSON_PROPERTY_UPDATE_TIME = "update_time"; + + private OptionalValue updateTime; + + public TemplateV1Impl() {} + + protected TemplateV1Impl( + OptionalValue channel, + OptionalValue createTime, + OptionalValue defaultTranslation, + OptionalValue description, + OptionalValue id, + OptionalValue> translations, + OptionalValue updateTime) { + this.channel = channel; + this.createTime = createTime; + this.defaultTranslation = defaultTranslation; + this.description = description; + this.id = id; + this.translations = translations; + this.updateTime = updateTime; + } + + @JsonIgnore + public TemplateChannel getChannel() { + return channel.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CHANNEL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue channel() { + return channel; + } + + @JsonIgnore + public Instant getCreateTime() { + return createTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue createTime() { + return createTime; + } + + @JsonIgnore + public String getDefaultTranslation() { + return defaultTranslation.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DEFAULT_TRANSLATION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue defaultTranslation() { + return defaultTranslation; + } + + @JsonIgnore + public String getDescription() { + return description.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DESCRIPTION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue description() { + return description; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue id() { + return id; + } + + @JsonIgnore + public List getTranslations() { + return translations.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TRANSLATIONS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> translations() { + return translations; + } + + @JsonIgnore + public Instant getUpdateTime() { + return updateTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue updateTime() { + return updateTime; + } + + /** Return true if this typeTemplate object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TemplateV1Impl typeTemplate = (TemplateV1Impl) o; + return Objects.equals(this.channel, typeTemplate.channel) + && Objects.equals(this.createTime, typeTemplate.createTime) + && Objects.equals(this.defaultTranslation, typeTemplate.defaultTranslation) + && Objects.equals(this.description, typeTemplate.description) + && Objects.equals(this.id, typeTemplate.id) + && Objects.equals(this.translations, typeTemplate.translations) + && Objects.equals(this.updateTime, typeTemplate.updateTime); + } + + @Override + public int hashCode() { + return Objects.hash( + channel, createTime, defaultTranslation, description, id, translations, updateTime); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TemplateV1Impl {\n"); + sb.append(" channel: ").append(toIndentedString(channel)).append("\n"); + sb.append(" createTime: ").append(toIndentedString(createTime)).append("\n"); + sb.append(" defaultTranslation: ").append(toIndentedString(defaultTranslation)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" translations: ").append(toIndentedString(translations)).append("\n"); + sb.append(" updateTime: ").append(toIndentedString(updateTime)).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 TemplateV1.Builder { + OptionalValue channel = OptionalValue.empty(); + OptionalValue createTime = OptionalValue.empty(); + OptionalValue defaultTranslation = OptionalValue.empty(); + OptionalValue description = OptionalValue.empty(); + OptionalValue id = OptionalValue.empty(); + OptionalValue> translations = OptionalValue.empty(); + OptionalValue updateTime = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_CHANNEL) + public Builder setChannel(TemplateChannel channel) { + this.channel = OptionalValue.of(channel); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + public Builder setCreateTime(Instant createTime) { + this.createTime = OptionalValue.of(createTime); + return this; + } + + @JsonProperty(JSON_PROPERTY_DEFAULT_TRANSLATION) + public Builder setDefaultTranslation(String defaultTranslation) { + this.defaultTranslation = OptionalValue.of(defaultTranslation); + return this; + } + + @JsonProperty(JSON_PROPERTY_DESCRIPTION) + public Builder setDescription(String description) { + this.description = OptionalValue.of(description); + return this; + } + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_TRANSLATIONS) + public Builder setTranslations(List translations) { + this.translations = OptionalValue.of(translations); + return this; + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + public Builder setUpdateTime(Instant updateTime) { + this.updateTime = OptionalValue.of(updateTime); + return this; + } + + public TemplateV1 build() { + return new TemplateV1Impl( + channel, createTime, defaultTranslation, description, id, translations, updateTime); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/internal/V1ListTemplatesResponseInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/internal/V1ListTemplatesResponseInternal.java new file mode 100644 index 00000000..6ea7561b --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/internal/V1ListTemplatesResponseInternal.java @@ -0,0 +1,56 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v1.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import java.util.List; + +/** V1ListTemplatesResponseInternal */ +@JsonDeserialize(builder = V1ListTemplatesResponseInternalImpl.Builder.class) +public interface V1ListTemplatesResponseInternal { + + /** + * Get templates + * + * @return templates + */ + List getTemplates(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new V1ListTemplatesResponseInternalImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param templates see getter + * @return Current builder + * @see #getTemplates + */ + Builder setTemplates(List templates); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + V1ListTemplatesResponseInternal build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/internal/V1ListTemplatesResponseInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/internal/V1ListTemplatesResponseInternalImpl.java new file mode 100644 index 00000000..c8f9b491 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v1/internal/V1ListTemplatesResponseInternalImpl.java @@ -0,0 +1,93 @@ +package com.sinch.sdk.domains.conversation.templates.models.v1.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.conversation.templates.models.v1.TemplateV1; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({V1ListTemplatesResponseInternalImpl.JSON_PROPERTY_TEMPLATES}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class V1ListTemplatesResponseInternalImpl implements V1ListTemplatesResponseInternal { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TEMPLATES = "templates"; + + private OptionalValue> templates; + + public V1ListTemplatesResponseInternalImpl() {} + + protected V1ListTemplatesResponseInternalImpl(OptionalValue> templates) { + this.templates = templates; + } + + @JsonIgnore + public List getTemplates() { + return templates.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TEMPLATES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> templates() { + return templates; + } + + /** Return true if this v1ListTemplatesResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + V1ListTemplatesResponseInternalImpl v1ListTemplatesResponse = + (V1ListTemplatesResponseInternalImpl) o; + return Objects.equals(this.templates, v1ListTemplatesResponse.templates); + } + + @Override + public int hashCode() { + return Objects.hash(templates); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class V1ListTemplatesResponseInternalImpl {\n"); + sb.append(" templates: ").append(toIndentedString(templates)).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 V1ListTemplatesResponseInternal.Builder { + OptionalValue> templates = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TEMPLATES) + public Builder setTemplates(List templates) { + this.templates = OptionalValue.of(templates); + return this; + } + + public V1ListTemplatesResponseInternal build() { + return new V1ListTemplatesResponseInternalImpl(templates); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverride.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverride.java new file mode 100644 index 00000000..8e0311cd --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverride.java @@ -0,0 +1,72 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v2; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.models.v1.TemplateReference; +import java.util.Map; + +/** ChannelTemplateOverride */ +@JsonDeserialize(builder = ChannelTemplateOverrideImpl.Builder.class) +public interface ChannelTemplateOverride { + + /** + * Get templateReference + * + * @return templateReference + */ + TemplateReference getTemplateReference(); + + /** + * A mapping between omni-template variables and the channel specific parameters. + * + * @return parameterMappings + */ + Map getParameterMappings(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new ChannelTemplateOverrideImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param templateReference see getter + * @return Current builder + * @see #getTemplateReference + */ + Builder setTemplateReference(TemplateReference templateReference); + + /** + * see getter + * + * @param parameterMappings see getter + * @return Current builder + * @see #getParameterMappings + */ + Builder setParameterMappings(Map parameterMappings); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + ChannelTemplateOverride build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverrideImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverrideImpl.java new file mode 100644 index 00000000..7cb49199 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/ChannelTemplateOverrideImpl.java @@ -0,0 +1,122 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +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.conversation.models.v1.TemplateReference; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + ChannelTemplateOverrideImpl.JSON_PROPERTY_TEMPLATE_REFERENCE, + ChannelTemplateOverrideImpl.JSON_PROPERTY_PARAMETER_MAPPINGS +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class ChannelTemplateOverrideImpl implements ChannelTemplateOverride { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TEMPLATE_REFERENCE = "template_reference"; + + private OptionalValue templateReference; + + public static final String JSON_PROPERTY_PARAMETER_MAPPINGS = "parameter_mappings"; + + private OptionalValue> parameterMappings; + + public ChannelTemplateOverrideImpl() {} + + protected ChannelTemplateOverrideImpl( + OptionalValue templateReference, + OptionalValue> parameterMappings) { + this.templateReference = templateReference; + this.parameterMappings = parameterMappings; + } + + @JsonIgnore + public TemplateReference getTemplateReference() { + return templateReference.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TEMPLATE_REFERENCE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue templateReference() { + return templateReference; + } + + @JsonIgnore + public Map getParameterMappings() { + return parameterMappings.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_PARAMETER_MAPPINGS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> parameterMappings() { + return parameterMappings; + } + + /** Return true if this ChannelTemplateOverride object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ChannelTemplateOverrideImpl channelTemplateOverride = (ChannelTemplateOverrideImpl) o; + return Objects.equals(this.templateReference, channelTemplateOverride.templateReference) + && Objects.equals(this.parameterMappings, channelTemplateOverride.parameterMappings); + } + + @Override + public int hashCode() { + return Objects.hash(templateReference, parameterMappings); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ChannelTemplateOverrideImpl {\n"); + sb.append(" templateReference: ").append(toIndentedString(templateReference)).append("\n"); + sb.append(" parameterMappings: ").append(toIndentedString(parameterMappings)).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 ChannelTemplateOverride.Builder { + OptionalValue templateReference = OptionalValue.empty(); + OptionalValue> parameterMappings = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TEMPLATE_REFERENCE) + public Builder setTemplateReference(TemplateReference templateReference) { + this.templateReference = OptionalValue.of(templateReference); + return this; + } + + @JsonProperty(JSON_PROPERTY_PARAMETER_MAPPINGS) + public Builder setParameterMappings(Map parameterMappings) { + this.parameterMappings = OptionalValue.of(parameterMappings); + return this; + } + + public ChannelTemplateOverride build() { + return new ChannelTemplateOverrideImpl(templateReference, parameterMappings); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationBase.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationBase.java new file mode 100644 index 00000000..e07b4e30 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationBase.java @@ -0,0 +1,134 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v2; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import java.time.Instant; +import java.util.List; +import java.util.Map; + +/** TemplateTranslationBase */ +@JsonDeserialize(builder = TemplateTranslationBaseImpl.Builder.class) +public interface TemplateTranslationBase { + + /** + * The BCP-47 language code, such as en-US or sr-Latn. For more + * information, see https://www.unicode.org/reports/tr35/#Unicode_locale_identifier. + * + * @return languageCode + */ + String getLanguageCode(); + + /** + * The version of the translation. + * + * @return version + */ + String getVersion(); + + /** + * Field to override the omnichannel template by referring to a channel-specific template. The key + * in the map must point to a valid conversation channel. Currently only WHATSAPP and + * KAKAOTALK are supported + * + * @return channelTemplateOverrides + */ + Map getChannelTemplateOverrides(); + + /** + * List of expected variables. Can be used for request validation. + * + * @return variables + */ + List getVariables(); + + /** + * Timestamp when the translation was created. + * + * @return createTime + */ + Instant getCreateTime(); + + /** + * Timestamp of when the translation was updated. + * + * @return updateTime + */ + Instant getUpdateTime(); + + /** Dedicated Builder */ + interface Builder> { + + /** + * see getter + * + * @param languageCode see getter + * @return Current builder + * @see #getLanguageCode + */ + B setLanguageCode(String languageCode); + + /** + * see getter + * + * @param version see getter + * @return Current builder + * @see #getVersion + */ + B setVersion(String version); + + /** + * see getter + * + * @param channelTemplateOverrides see getter + * @return Current builder + * @see #getChannelTemplateOverrides + */ + B setChannelTemplateOverrides( + Map channelTemplateOverrides); + + /** + * see getter + * + * @param variables see getter + * @return Current builder + * @see #getVariables + */ + B setVariables(List variables); + + /** + * see getter + * + * @param createTime see getter + * @return Current builder + * @see #getCreateTime + */ + B setCreateTime(Instant createTime); + + /** + * see getter + * + * @param updateTime see getter + * @return Current builder + * @see #getUpdateTime + */ + B setUpdateTime(Instant updateTime); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TemplateTranslationBase build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationBaseImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationBaseImpl.java new file mode 100644 index 00000000..b3ccdb55 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateTranslationBaseImpl.java @@ -0,0 +1,527 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +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.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.carousel.CarouselMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.choice.ChoiceMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.contactinfo.ContactInfoMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.list.ListMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.location.LocationMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.media.MediaMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessage; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import java.time.Instant; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@JsonPropertyOrder({ + TemplateTranslationBaseImpl.JSON_PROPERTY_LANGUAGE_CODE, + TemplateTranslationBaseImpl.JSON_PROPERTY_VERSION, + TemplateTranslationBaseImpl.JSON_PROPERTY_CHANNEL_TEMPLATE_OVERRIDES, + TemplateTranslationBaseImpl.JSON_PROPERTY_VARIABLES, + TemplateTranslationBaseImpl.JSON_PROPERTY_CREATE_TIME, + TemplateTranslationBaseImpl.JSON_PROPERTY_UPDATE_TIME, + TemplateTranslationBaseImpl.JSON_PROPERTY_CARD_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_CAROUSEL_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_CHOICE_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_LOCATION_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_MEDIA_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_TEMPLATE_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_TEXT_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_LIST_MESSAGE, + TemplateTranslationBaseImpl.JSON_PROPERTY_CONTACT_INFO_MESSAGE +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TemplateTranslationBaseImpl implements TemplateTranslationBase { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_LANGUAGE_CODE = "language_code"; + + private OptionalValue languageCode; + + public static final String JSON_PROPERTY_VERSION = "version"; + + private OptionalValue version; + + public static final String JSON_PROPERTY_CHANNEL_TEMPLATE_OVERRIDES = + "channel_template_overrides"; + + private OptionalValue> channelTemplateOverrides; + + public static final String JSON_PROPERTY_VARIABLES = "variables"; + + private OptionalValue> variables; + + public static final String JSON_PROPERTY_CREATE_TIME = "create_time"; + + private OptionalValue createTime; + + public static final String JSON_PROPERTY_UPDATE_TIME = "update_time"; + + private OptionalValue updateTime; + + public static final String JSON_PROPERTY_CARD_MESSAGE = "card_message"; + + private OptionalValue cardMessage; + + public static final String JSON_PROPERTY_CAROUSEL_MESSAGE = "carousel_message"; + + private OptionalValue carouselMessage; + + public static final String JSON_PROPERTY_CHOICE_MESSAGE = "choice_message"; + + private OptionalValue choiceMessage; + + public static final String JSON_PROPERTY_LOCATION_MESSAGE = "location_message"; + + private OptionalValue locationMessage; + + public static final String JSON_PROPERTY_MEDIA_MESSAGE = "media_message"; + + private OptionalValue mediaMessage; + + public static final String JSON_PROPERTY_TEMPLATE_MESSAGE = "template_message"; + + private OptionalValue templateMessage; + + public static final String JSON_PROPERTY_TEXT_MESSAGE = "text_message"; + + private OptionalValue textMessage; + + public static final String JSON_PROPERTY_LIST_MESSAGE = "list_message"; + + private OptionalValue listMessage; + + public static final String JSON_PROPERTY_CONTACT_INFO_MESSAGE = "contact_info_message"; + + private OptionalValue contactInfoMessage; + + public TemplateTranslationBaseImpl() {} + + protected TemplateTranslationBaseImpl( + OptionalValue languageCode, + OptionalValue version, + OptionalValue> channelTemplateOverrides, + OptionalValue> variables, + OptionalValue createTime, + OptionalValue updateTime, + OptionalValue cardMessage, + OptionalValue carouselMessage, + OptionalValue choiceMessage, + OptionalValue locationMessage, + OptionalValue mediaMessage, + OptionalValue templateMessage, + OptionalValue textMessage, + OptionalValue listMessage, + OptionalValue contactInfoMessage) { + this.languageCode = languageCode; + this.version = version; + this.channelTemplateOverrides = channelTemplateOverrides; + this.variables = variables; + this.createTime = createTime; + this.updateTime = updateTime; + this.cardMessage = cardMessage; + this.carouselMessage = carouselMessage; + this.choiceMessage = choiceMessage; + this.locationMessage = locationMessage; + this.mediaMessage = mediaMessage; + this.templateMessage = templateMessage; + this.textMessage = textMessage; + this.listMessage = listMessage; + this.contactInfoMessage = contactInfoMessage; + } + + @JsonIgnore + public String getLanguageCode() { + return languageCode.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_LANGUAGE_CODE) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + public OptionalValue languageCode() { + return languageCode; + } + + @JsonIgnore + public String getVersion() { + return version.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_VERSION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue version() { + return version; + } + + @JsonIgnore + public Map getChannelTemplateOverrides() { + return channelTemplateOverrides.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CHANNEL_TEMPLATE_OVERRIDES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> + channelTemplateOverrides() { + return channelTemplateOverrides; + } + + @JsonIgnore + public List getVariables() { + return variables.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_VARIABLES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> variables() { + return variables; + } + + @JsonIgnore + public Instant getCreateTime() { + return createTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue createTime() { + return createTime; + } + + @JsonIgnore + public Instant getUpdateTime() { + return updateTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue updateTime() { + return updateTime; + } + + @JsonIgnore + public CardMessage getCardMessage() { + return cardMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CARD_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue cardMessage() { + return cardMessage; + } + + @JsonIgnore + public CarouselMessage getCarouselMessage() { + return carouselMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CAROUSEL_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue carouselMessage() { + return carouselMessage; + } + + @JsonIgnore + public ChoiceMessage getChoiceMessage() { + return choiceMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CHOICE_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue choiceMessage() { + return choiceMessage; + } + + @JsonIgnore + public LocationMessage getLocationMessage() { + return locationMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_LOCATION_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue locationMessage() { + return locationMessage; + } + + @JsonIgnore + public MediaMessage getMediaMessage() { + return mediaMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_MEDIA_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue mediaMessage() { + return mediaMessage; + } + + @JsonIgnore + public TemplateMessage getTemplateMessage() { + return templateMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TEMPLATE_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue templateMessage() { + return templateMessage; + } + + @JsonIgnore + public TextMessage getTextMessage() { + return textMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TEXT_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue textMessage() { + return textMessage; + } + + @JsonIgnore + public ListMessage getListMessage() { + return listMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_LIST_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue listMessage() { + return listMessage; + } + + @JsonIgnore + public ContactInfoMessage getContactInfoMessage() { + return contactInfoMessage.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CONTACT_INFO_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue contactInfoMessage() { + return contactInfoMessage; + } + + /** Return true if this v2TemplateTranslation object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TemplateTranslationBaseImpl v2TemplateTranslation = (TemplateTranslationBaseImpl) o; + return Objects.equals(this.languageCode, v2TemplateTranslation.languageCode) + && Objects.equals(this.version, v2TemplateTranslation.version) + && Objects.equals( + this.channelTemplateOverrides, v2TemplateTranslation.channelTemplateOverrides) + && Objects.equals(this.variables, v2TemplateTranslation.variables) + && Objects.equals(this.createTime, v2TemplateTranslation.createTime) + && Objects.equals(this.updateTime, v2TemplateTranslation.updateTime) + && Objects.equals(this.cardMessage, v2TemplateTranslation.cardMessage) + && Objects.equals(this.carouselMessage, v2TemplateTranslation.carouselMessage) + && Objects.equals(this.choiceMessage, v2TemplateTranslation.choiceMessage) + && Objects.equals(this.locationMessage, v2TemplateTranslation.locationMessage) + && Objects.equals(this.mediaMessage, v2TemplateTranslation.mediaMessage) + && Objects.equals(this.templateMessage, v2TemplateTranslation.templateMessage) + && Objects.equals(this.textMessage, v2TemplateTranslation.textMessage) + && Objects.equals(this.listMessage, v2TemplateTranslation.listMessage) + && Objects.equals(this.contactInfoMessage, v2TemplateTranslation.contactInfoMessage); + } + + @Override + public int hashCode() { + return Objects.hash( + languageCode, + version, + channelTemplateOverrides, + variables, + createTime, + updateTime, + cardMessage, + carouselMessage, + choiceMessage, + locationMessage, + mediaMessage, + templateMessage, + textMessage, + listMessage, + contactInfoMessage); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TemplateTranslationBaseImpl {\n"); + sb.append(" languageCode: ").append(toIndentedString(languageCode)).append("\n"); + sb.append(" version: ").append(toIndentedString(version)).append("\n"); + sb.append(" channelTemplateOverrides: ") + .append(toIndentedString(channelTemplateOverrides)) + .append("\n"); + sb.append(" variables: ").append(toIndentedString(variables)).append("\n"); + sb.append(" createTime: ").append(toIndentedString(createTime)).append("\n"); + sb.append(" updateTime: ").append(toIndentedString(updateTime)).append("\n"); + sb.append(" cardMessage: ").append(toIndentedString(cardMessage)).append("\n"); + sb.append(" carouselMessage: ").append(toIndentedString(carouselMessage)).append("\n"); + sb.append(" choiceMessage: ").append(toIndentedString(choiceMessage)).append("\n"); + sb.append(" locationMessage: ").append(toIndentedString(locationMessage)).append("\n"); + sb.append(" mediaMessage: ").append(toIndentedString(mediaMessage)).append("\n"); + sb.append(" templateMessage: ").append(toIndentedString(templateMessage)).append("\n"); + sb.append(" textMessage: ").append(toIndentedString(textMessage)).append("\n"); + sb.append(" listMessage: ").append(toIndentedString(listMessage)).append("\n"); + sb.append(" contactInfoMessage: ").append(toIndentedString(contactInfoMessage)).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 TemplateTranslationBase.Builder { + OptionalValue languageCode = OptionalValue.empty(); + OptionalValue version = OptionalValue.empty(); + OptionalValue> channelTemplateOverrides = + OptionalValue.empty(); + OptionalValue> variables = OptionalValue.empty(); + OptionalValue createTime = OptionalValue.empty(); + OptionalValue updateTime = OptionalValue.empty(); + OptionalValue cardMessage = OptionalValue.empty(); + OptionalValue carouselMessage = OptionalValue.empty(); + OptionalValue choiceMessage = OptionalValue.empty(); + OptionalValue locationMessage = OptionalValue.empty(); + OptionalValue mediaMessage = OptionalValue.empty(); + OptionalValue templateMessage = OptionalValue.empty(); + OptionalValue textMessage = OptionalValue.empty(); + OptionalValue listMessage = OptionalValue.empty(); + OptionalValue contactInfoMessage = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_LANGUAGE_CODE) + public B setLanguageCode(String languageCode) { + this.languageCode = OptionalValue.of(languageCode); + return self(); + } + + @JsonProperty(JSON_PROPERTY_VERSION) + public B setVersion(String version) { + this.version = OptionalValue.of(version); + return self(); + } + + @JsonProperty(JSON_PROPERTY_CHANNEL_TEMPLATE_OVERRIDES) + public B setChannelTemplateOverrides( + Map channelTemplateOverrides) { + this.channelTemplateOverrides = OptionalValue.of(channelTemplateOverrides); + return self(); + } + + @JsonProperty(JSON_PROPERTY_VARIABLES) + public B setVariables(List variables) { + this.variables = OptionalValue.of(variables); + return self(); + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + public B setCreateTime(Instant createTime) { + this.createTime = OptionalValue.of(createTime); + return self(); + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + public B setUpdateTime(Instant updateTime) { + this.updateTime = OptionalValue.of(updateTime); + return self(); + } + + @JsonProperty(JSON_PROPERTY_CARD_MESSAGE) + public B setCardMessage(CardMessage cardMessage) { + this.cardMessage = OptionalValue.of(cardMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_CAROUSEL_MESSAGE) + public B setCarouselMessage(CarouselMessage carouselMessage) { + this.carouselMessage = OptionalValue.of(carouselMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_CHOICE_MESSAGE) + public B setChoiceMessage(ChoiceMessage choiceMessage) { + this.choiceMessage = OptionalValue.of(choiceMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_LOCATION_MESSAGE) + public B setLocationMessage(LocationMessage locationMessage) { + this.locationMessage = OptionalValue.of(locationMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_MEDIA_MESSAGE) + public B setMediaMessage(MediaMessage mediaMessage) { + this.mediaMessage = OptionalValue.of(mediaMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_TEMPLATE_MESSAGE) + public B setTemplateMessage(TemplateMessage templateMessage) { + this.templateMessage = OptionalValue.of(templateMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_TEXT_MESSAGE) + public B setTextMessage(TextMessage textMessage) { + this.textMessage = OptionalValue.of(textMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_LIST_MESSAGE) + public B setListMessage(ListMessage listMessage) { + this.listMessage = OptionalValue.of(listMessage); + return self(); + } + + @JsonProperty(JSON_PROPERTY_CONTACT_INFO_MESSAGE) + public B setContactInfoMessage(ContactInfoMessage contactInfoMessage) { + this.contactInfoMessage = OptionalValue.of(contactInfoMessage); + return self(); + } + + @SuppressWarnings("unchecked") + protected B self() { + return (B) this; + } + + public TemplateTranslationBase build() { + return new TemplateTranslationBaseImpl( + languageCode, + version, + channelTemplateOverrides, + variables, + createTime, + updateTime, + cardMessage, + carouselMessage, + choiceMessage, + locationMessage, + mediaMessage, + templateMessage, + textMessage, + listMessage, + contactInfoMessage); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateV2.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateV2.java new file mode 100644 index 00000000..66155538 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateV2.java @@ -0,0 +1,156 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v2; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.time.Instant; +import java.util.Collection; + +/** TemplateV2 */ +@JsonDeserialize(builder = TemplateV2Impl.Builder.class) +public interface TemplateV2 { + + /** + * The id of the template. Specify this yourself during creation. Otherwise, we will generate an + * ID for you. This must be unique for a given project. + * + * @return id + */ + String getId(); + + /** + * The description of the template. + * + * @return description + */ + String getDescription(); + + /** + * The version of the template. While creating a template, this will be defaulted to 1. When + * updating a template, you must supply the latest version of the template in order for the update + * to be successful. + * + * @return version + */ + Integer getVersion(); + + /** + * The default translation to use if not specified. Specified as a BCP-47 language_code + * and the language_code must exist in the translations list. + * + * @return defaultTranslation + */ + String getDefaultTranslation(); + + /** + * Get translations + * + * @return translations + */ + Collection getTranslations(); + + /** + * Timestamp when the template was created. + * + * @return createTime + */ + Instant getCreateTime(); + + /** + * Timestamp when the template was updated. + * + * @return updateTime + */ + Instant getUpdateTime(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new TemplateV2Impl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param id see getter + * @return Current builder + * @see #getId + */ + Builder setId(String id); + + /** + * see getter + * + * @param description see getter + * @return Current builder + * @see #getDescription + */ + Builder setDescription(String description); + + /** + * see getter + * + * @param version see getter + * @return Current builder + * @see #getVersion + */ + Builder setVersion(Integer version); + + /** + * see getter + * + * @param defaultTranslation see getter + * @return Current builder + * @see #getDefaultTranslation + */ + Builder setDefaultTranslation(String defaultTranslation); + + /** + * see getter + * + * @param translations see getter + * @return Current builder + * @see #getTranslations + */ + Builder setTranslations(Collection translations); + + /** + * see getter + * + * @param createTime see getter + * @return Current builder + * @see #getCreateTime + */ + Builder setCreateTime(Instant createTime); + + /** + * see getter + * + * @param updateTime see getter + * @return Current builder + * @see #getUpdateTime + */ + Builder setUpdateTime(Instant updateTime); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + TemplateV2 build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateV2Impl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateV2Impl.java new file mode 100644 index 00000000..598fab5a --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/TemplateV2Impl.java @@ -0,0 +1,259 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2; + +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.Collection; +import java.util.Objects; + +@JsonPropertyOrder({ + TemplateV2Impl.JSON_PROPERTY_ID, + TemplateV2Impl.JSON_PROPERTY_DESCRIPTION, + TemplateV2Impl.JSON_PROPERTY_VERSION, + TemplateV2Impl.JSON_PROPERTY_DEFAULT_TRANSLATION, + TemplateV2Impl.JSON_PROPERTY_TRANSLATIONS, + TemplateV2Impl.JSON_PROPERTY_CREATE_TIME, + TemplateV2Impl.JSON_PROPERTY_UPDATE_TIME +}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class TemplateV2Impl implements TemplateV2 { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_ID = "id"; + + private OptionalValue id; + + public static final String JSON_PROPERTY_DESCRIPTION = "description"; + + private OptionalValue description; + + public static final String JSON_PROPERTY_VERSION = "version"; + + private OptionalValue version; + + public static final String JSON_PROPERTY_DEFAULT_TRANSLATION = "default_translation"; + + private OptionalValue defaultTranslation; + + public static final String JSON_PROPERTY_TRANSLATIONS = "translations"; + + private OptionalValue> translations; + + public static final String JSON_PROPERTY_CREATE_TIME = "create_time"; + + private OptionalValue createTime; + + public static final String JSON_PROPERTY_UPDATE_TIME = "update_time"; + + private OptionalValue updateTime; + + public TemplateV2Impl() {} + + protected TemplateV2Impl( + OptionalValue id, + OptionalValue description, + OptionalValue version, + OptionalValue defaultTranslation, + OptionalValue> translations, + OptionalValue createTime, + OptionalValue updateTime) { + this.id = id; + this.description = description; + this.version = version; + this.defaultTranslation = defaultTranslation; + this.translations = translations; + this.createTime = createTime; + this.updateTime = updateTime; + } + + @JsonIgnore + public String getId() { + return id.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue id() { + return id; + } + + @JsonIgnore + public String getDescription() { + return description.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DESCRIPTION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue description() { + return description; + } + + @JsonIgnore + public Integer getVersion() { + return version.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_VERSION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue version() { + return version; + } + + @JsonIgnore + public String getDefaultTranslation() { + return defaultTranslation.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_DEFAULT_TRANSLATION) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue defaultTranslation() { + return defaultTranslation; + } + + @JsonIgnore + public Collection getTranslations() { + return translations.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TRANSLATIONS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> translations() { + return translations; + } + + @JsonIgnore + public Instant getCreateTime() { + return createTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue createTime() { + return createTime; + } + + @JsonIgnore + public Instant getUpdateTime() { + return updateTime.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue updateTime() { + return updateTime; + } + + /** Return true if this v2Template object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + TemplateV2Impl v2Template = (TemplateV2Impl) o; + return Objects.equals(this.id, v2Template.id) + && Objects.equals(this.description, v2Template.description) + && Objects.equals(this.version, v2Template.version) + && Objects.equals(this.defaultTranslation, v2Template.defaultTranslation) + && Objects.equals(this.translations, v2Template.translations) + && Objects.equals(this.createTime, v2Template.createTime) + && Objects.equals(this.updateTime, v2Template.updateTime); + } + + @Override + public int hashCode() { + return Objects.hash( + id, description, version, defaultTranslation, translations, createTime, updateTime); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TemplateV2Impl {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" version: ").append(toIndentedString(version)).append("\n"); + sb.append(" defaultTranslation: ").append(toIndentedString(defaultTranslation)).append("\n"); + sb.append(" translations: ").append(toIndentedString(translations)).append("\n"); + sb.append(" createTime: ").append(toIndentedString(createTime)).append("\n"); + sb.append(" updateTime: ").append(toIndentedString(updateTime)).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 TemplateV2.Builder { + OptionalValue id = OptionalValue.empty(); + OptionalValue description = OptionalValue.empty(); + OptionalValue version = OptionalValue.empty(); + OptionalValue defaultTranslation = OptionalValue.empty(); + OptionalValue> translations = OptionalValue.empty(); + OptionalValue createTime = OptionalValue.empty(); + OptionalValue updateTime = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_ID) + public Builder setId(String id) { + this.id = OptionalValue.of(id); + return this; + } + + @JsonProperty(JSON_PROPERTY_DESCRIPTION) + public Builder setDescription(String description) { + this.description = OptionalValue.of(description); + return this; + } + + @JsonProperty(JSON_PROPERTY_VERSION) + public Builder setVersion(Integer version) { + this.version = OptionalValue.of(version); + return this; + } + + @JsonProperty(JSON_PROPERTY_DEFAULT_TRANSLATION) + public Builder setDefaultTranslation(String defaultTranslation) { + this.defaultTranslation = OptionalValue.of(defaultTranslation); + return this; + } + + @JsonProperty(JSON_PROPERTY_TRANSLATIONS) + public Builder setTranslations(Collection translations) { + this.translations = OptionalValue.of(translations); + return this; + } + + @JsonProperty(JSON_PROPERTY_CREATE_TIME) + public Builder setCreateTime(Instant createTime) { + this.createTime = OptionalValue.of(createTime); + return this; + } + + @JsonProperty(JSON_PROPERTY_UPDATE_TIME) + public Builder setUpdateTime(Instant updateTime) { + this.updateTime = OptionalValue.of(updateTime); + return this; + } + + public TemplateV2 build() { + return new TemplateV2Impl( + id, description, version, defaultTranslation, translations, createTime, updateTime); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTemplatesResponseInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTemplatesResponseInternal.java new file mode 100644 index 00000000..f72c975d --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTemplatesResponseInternal.java @@ -0,0 +1,56 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v2.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import java.util.List; + +/** V2ListTemplatesResponseInternal */ +@JsonDeserialize(builder = V2ListTemplatesResponseInternalImpl.Builder.class) +public interface V2ListTemplatesResponseInternal { + + /** + * Get templates + * + * @return templates + */ + List getTemplates(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new V2ListTemplatesResponseInternalImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param templates see getter + * @return Current builder + * @see #getTemplates + */ + Builder setTemplates(List templates); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + V2ListTemplatesResponseInternal build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTemplatesResponseInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTemplatesResponseInternalImpl.java new file mode 100644 index 00000000..3226a8f0 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTemplatesResponseInternalImpl.java @@ -0,0 +1,93 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2.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.conversation.templates.models.v2.TemplateV2; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({V2ListTemplatesResponseInternalImpl.JSON_PROPERTY_TEMPLATES}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class V2ListTemplatesResponseInternalImpl implements V2ListTemplatesResponseInternal { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TEMPLATES = "templates"; + + private OptionalValue> templates; + + public V2ListTemplatesResponseInternalImpl() {} + + protected V2ListTemplatesResponseInternalImpl(OptionalValue> templates) { + this.templates = templates; + } + + @JsonIgnore + public List getTemplates() { + return templates.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TEMPLATES) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> templates() { + return templates; + } + + /** Return true if this v2ListTemplatesResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + V2ListTemplatesResponseInternalImpl v2ListTemplatesResponse = + (V2ListTemplatesResponseInternalImpl) o; + return Objects.equals(this.templates, v2ListTemplatesResponse.templates); + } + + @Override + public int hashCode() { + return Objects.hash(templates); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class V2ListTemplatesResponseInternalImpl {\n"); + sb.append(" templates: ").append(toIndentedString(templates)).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 V2ListTemplatesResponseInternal.Builder { + OptionalValue> templates = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TEMPLATES) + public Builder setTemplates(List templates) { + this.templates = OptionalValue.of(templates); + return this; + } + + public V2ListTemplatesResponseInternal build() { + return new V2ListTemplatesResponseInternalImpl(templates); + } + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTranslationsResponseInternal.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTranslationsResponseInternal.java new file mode 100644 index 00000000..dda8502f --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTranslationsResponseInternal.java @@ -0,0 +1,56 @@ +/* + * Template Management API + * + * OpenAPI document version: 457aacb5 + * 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.conversation.templates.models.v2.internal; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslationBase; +import java.util.List; + +/** V2ListTranslationsResponseInternal */ +@JsonDeserialize(builder = V2ListTranslationsResponseInternalImpl.Builder.class) +public interface V2ListTranslationsResponseInternal { + + /** + * Get translations + * + * @return translations + */ + List getTranslations(); + + /** + * Getting builder + * + * @return New Builder instance + */ + static Builder builder() { + return new V2ListTranslationsResponseInternalImpl.Builder(); + } + + /** Dedicated Builder */ + interface Builder { + + /** + * see getter + * + * @param translations see getter + * @return Current builder + * @see #getTranslations + */ + Builder setTranslations(List translations); + + /** + * Create instance + * + * @return The instance build with current builder values + */ + V2ListTranslationsResponseInternal build(); + } +} diff --git a/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTranslationsResponseInternalImpl.java b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTranslationsResponseInternalImpl.java new file mode 100644 index 00000000..f7304a72 --- /dev/null +++ b/openapi-contracts/src/main/com/sinch/sdk/domains/conversation/templates/models/v2/internal/V2ListTranslationsResponseInternalImpl.java @@ -0,0 +1,94 @@ +package com.sinch.sdk.domains.conversation.templates.models.v2.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.conversation.templates.models.v2.TemplateTranslationBase; +import java.util.List; +import java.util.Objects; + +@JsonPropertyOrder({V2ListTranslationsResponseInternalImpl.JSON_PROPERTY_TRANSLATIONS}) +@JsonFilter("uninitializedFilter") +@JsonInclude(value = JsonInclude.Include.CUSTOM) +public class V2ListTranslationsResponseInternalImpl implements V2ListTranslationsResponseInternal { + private static final long serialVersionUID = 1L; + + public static final String JSON_PROPERTY_TRANSLATIONS = "translations"; + + private OptionalValue> translations; + + public V2ListTranslationsResponseInternalImpl() {} + + protected V2ListTranslationsResponseInternalImpl( + OptionalValue> translations) { + this.translations = translations; + } + + @JsonIgnore + public List getTranslations() { + return translations.orElse(null); + } + + @JsonProperty(JSON_PROPERTY_TRANSLATIONS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + public OptionalValue> translations() { + return translations; + } + + /** Return true if this v2ListTranslationsResponse object is equal to o. */ + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + V2ListTranslationsResponseInternalImpl v2ListTranslationsResponse = + (V2ListTranslationsResponseInternalImpl) o; + return Objects.equals(this.translations, v2ListTranslationsResponse.translations); + } + + @Override + public int hashCode() { + return Objects.hash(translations); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class V2ListTranslationsResponseInternalImpl {\n"); + sb.append(" translations: ").append(toIndentedString(translations)).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 V2ListTranslationsResponseInternal.Builder { + OptionalValue> translations = OptionalValue.empty(); + + @JsonProperty(JSON_PROPERTY_TRANSLATIONS) + public Builder setTranslations(List translations) { + this.translations = OptionalValue.of(translations); + return this; + } + + public V2ListTranslationsResponseInternal build() { + return new V2ListTranslationsResponseInternalImpl(translations); + } + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplatesBaseTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplatesBaseTest.java new file mode 100644 index 00000000..3f5bd009 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/api/templates/adapters/TemplatesBaseTest.java @@ -0,0 +1,11 @@ +package com.sinch.sdk.domains.conversation.api.templates.adapters; + +import com.sinch.sdk.BaseTest; + +public class TemplatesBaseTest extends BaseTest { + + static { + // faking a service init to trigger dedicated serializers initialization + TemplatesService.LocalLazyInit.init(); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/TemplateVariableDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/TemplateVariableDtoTest.java new file mode 100644 index 00000000..a3533bc0 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/TemplateVariableDtoTest.java @@ -0,0 +1,35 @@ +package com.sinch.sdk.domains.conversation.models.templates; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class TemplateVariableDtoTest extends TemplatesBaseTest { + + public static TemplateVariable expectedDto = + TemplateVariable.builder().setKey("key value").setPreviewValue("preview value").build(); + + @GivenTextResource("/domains/conversation/templates/TemplateVariableDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, TemplateVariable.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/TemplateTranslationDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/TemplateTranslationDtoTest.java new file mode 100644 index 00000000..29d89660 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/TemplateTranslationDtoTest.java @@ -0,0 +1,45 @@ +package com.sinch.sdk.domains.conversation.models.templates.v1; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.TemplateVariableDtoTest; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateTranslation; +import java.time.Instant; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class TemplateTranslationDtoTest extends TemplatesBaseTest { + + public static TemplateTranslation expectedDto = + TemplateTranslation.builder() + .setLanguageCode("fr-FR") + .setContent("{\"text_message\":{\"text\":\"Message from a template v1.\"}}") + .setVersion("1") + .setCreateTime(Instant.parse("2024-07-07T02:59:59Z")) + .setUpdateTime(Instant.parse("2024-07-07T06:07:44Z")) + .setVariables(Arrays.asList(TemplateVariableDtoTest.expectedDto)) + .build(); + + @GivenTextResource("/domains/conversation/templates/v1/TemplateTranslationDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, TemplateTranslation.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/TemplateV1DtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/TemplateV1DtoTest.java new file mode 100644 index 00000000..bb078ad5 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/TemplateV1DtoTest.java @@ -0,0 +1,46 @@ +package com.sinch.sdk.domains.conversation.models.templates.v1; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateChannel; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import java.time.Instant; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class TemplateV1DtoTest extends TemplatesBaseTest { + + public static TemplateV1 expectedDto = + TemplateV1.builder() + .setChannel(TemplateChannel.RCS) + .setCreateTime(Instant.parse("2024-08-26T06:00:00Z")) + .setDefaultTranslation("fr-FR") + .setDescription("template description value") + .setId("id value") + .setTranslations(Arrays.asList(TemplateTranslationDtoTest.expectedDto)) + .setUpdateTime(Instant.parse("2024-08-26T06:07:44Z")) + .build(); + + @GivenTextResource("/domains/conversation/templates/v1/TemplateV1Dto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, TemplateV1.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/internal/V1ListTemplatesResponseInternalDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/internal/V1ListTemplatesResponseInternalDtoTest.java new file mode 100644 index 00000000..6dfb2565 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v1/internal/V1ListTemplatesResponseInternalDtoTest.java @@ -0,0 +1,40 @@ +package com.sinch.sdk.domains.conversation.models.templates.v1.internal; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.v1.TemplateV1DtoTest; +import com.sinch.sdk.domains.conversation.templates.models.v1.internal.V1ListTemplatesResponseInternal; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class V1ListTemplatesResponseInternalDtoTest extends TemplatesBaseTest { + + public static V1ListTemplatesResponseInternal expectedDto = + V1ListTemplatesResponseInternal.builder() + .setTemplates(Arrays.asList(TemplateV1DtoTest.expectedDto)) + .build(); + + @GivenTextResource( + "/domains/conversation/templates/v1/internal/V1ListTemplatesResponseInternalDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, V1ListTemplatesResponseInternal.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/ChannelTemplateOverrideDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/ChannelTemplateOverrideDtoTest.java new file mode 100644 index 00000000..58f0aa6f --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/ChannelTemplateOverrideDtoTest.java @@ -0,0 +1,40 @@ +package com.sinch.sdk.domains.conversation.models.templates.v2; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.v1.TemplateReferenceDtoTest; +import com.sinch.sdk.domains.conversation.templates.models.v2.ChannelTemplateOverride; +import java.util.Collections; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class ChannelTemplateOverrideDtoTest extends TemplatesBaseTest { + + public static ChannelTemplateOverride expectedDto = + ChannelTemplateOverride.builder() + .setParameterMappings(Collections.singletonMap("a key", "a value")) + .setTemplateReference(TemplateReferenceDtoTest.templateReferenceDto) + .build(); + + @GivenTextResource("/domains/conversation/templates/v2/ChannelTemplateOverrideDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, ChannelTemplateOverride.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/TemplateTranslationDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/TemplateTranslationDtoTest.java new file mode 100644 index 00000000..7a632eb3 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/TemplateTranslationDtoTest.java @@ -0,0 +1,51 @@ +package com.sinch.sdk.domains.conversation.models.templates.v2; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.TemplateVariableDtoTest; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.template.TemplateMessageDtoTest; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import java.time.Instant; +import java.util.Arrays; +import java.util.Collections; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class TemplateTranslationDtoTest extends TemplatesBaseTest { + + public static TemplateTranslation expectedDto = + TemplateTranslation.builder() + .setMessage(TemplateMessageDtoTest.templateMessageDto) + .setLanguageCode("fr-FR") + .setVersion("1") + .setChannelTemplateOverrides( + Collections.singletonMap( + ConversationChannel.KAKAOTALK, ChannelTemplateOverrideDtoTest.expectedDto)) + .setVariables(Arrays.asList(TemplateVariableDtoTest.expectedDto)) + .setCreateTime(Instant.parse("2024-07-07T02:59:59Z")) + .setUpdateTime(Instant.parse("2024-07-07T06:07:44Z")) + .build(); + + @GivenTextResource("/domains/conversation/templates/v2/TemplateTranslationDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, TemplateTranslation.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/TemplateV2DtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/TemplateV2DtoTest.java new file mode 100644 index 00000000..aa025e42 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/TemplateV2DtoTest.java @@ -0,0 +1,44 @@ +package com.sinch.sdk.domains.conversation.models.templates.v2; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import java.time.Instant; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class TemplateV2DtoTest extends TemplatesBaseTest { + + public static TemplateV2 expectedDto = + TemplateV2.builder() + .setTranslations(Arrays.asList(TemplateTranslationDtoTest.expectedDto)) + .setDefaultTranslation("fr-FR") + .setDescription("template description value") + .setVersion(1) + .setCreateTime(Instant.parse("2024-08-26T06:00:00Z")) + .setUpdateTime(Instant.parse("2024-08-26T06:07:44Z")) + .build(); + + @GivenTextResource("/domains/conversation/templates/v2/TemplateV2Dto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, TemplateV2.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/internal/V2ListTemplatesResponseInternalDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/internal/V2ListTemplatesResponseInternalDtoTest.java new file mode 100644 index 00000000..b4749624 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/internal/V2ListTemplatesResponseInternalDtoTest.java @@ -0,0 +1,40 @@ +package com.sinch.sdk.domains.conversation.models.templates.v2.internal; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.v2.TemplateV2DtoTest; +import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTemplatesResponseInternal; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class V2ListTemplatesResponseInternalDtoTest extends TemplatesBaseTest { + + public static V2ListTemplatesResponseInternal expectedDto = + V2ListTemplatesResponseInternal.builder() + .setTemplates(Arrays.asList(TemplateV2DtoTest.expectedDto)) + .build(); + + @GivenTextResource( + "/domains/conversation/templates/v2/internal/V2ListTemplatesResponseInternalDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, V2ListTemplatesResponseInternal.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/internal/V2ListTranslationsResponseInternalDtoTest.java b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/internal/V2ListTranslationsResponseInternalDtoTest.java new file mode 100644 index 00000000..a9c40ec9 --- /dev/null +++ b/openapi-contracts/src/test/java/com/sinch/sdk/domains/conversation/models/templates/v2/internal/V2ListTranslationsResponseInternalDtoTest.java @@ -0,0 +1,40 @@ +package com.sinch.sdk.domains.conversation.models.templates.v2.internal; + +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.templates.adapters.TemplatesBaseTest; +import com.sinch.sdk.domains.conversation.models.templates.v2.TemplateTranslationDtoTest; +import com.sinch.sdk.domains.conversation.templates.models.v2.internal.V2ListTranslationsResponseInternal; +import java.util.Arrays; +import org.json.JSONException; +import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; + +@TestWithResources +public class V2ListTranslationsResponseInternalDtoTest extends TemplatesBaseTest { + + public static V2ListTranslationsResponseInternal expectedDto = + V2ListTranslationsResponseInternal.builder() + .setTranslations(Arrays.asList(TemplateTranslationDtoTest.expectedDto)) + .build(); + + @GivenTextResource( + "/domains/conversation/templates/v2/internal/V2ListTranslationsResponseInternalDto.json") + String json; + + @Test + void serialize() throws JsonProcessingException, JSONException { + String serializedString = objectMapper.writeValueAsString(expectedDto); + + JSONAssert.assertEquals(json, serializedString, true); + } + + @Test + void deserialize() throws JsonProcessingException { + Object deserialized = objectMapper.readValue(json, V2ListTranslationsResponseInternal.class); + + TestHelpers.recursiveEquals(deserialized, expectedDto); + } +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/TemplateVariableDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/TemplateVariableDto.json new file mode 100644 index 00000000..bc8e0976 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/TemplateVariableDto.json @@ -0,0 +1,4 @@ +{ + "key": "key value", + "preview_value": "preview value" +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v1/TemplateTranslationDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v1/TemplateTranslationDto.json new file mode 100644 index 00000000..30ff0849 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v1/TemplateTranslationDto.json @@ -0,0 +1,13 @@ +{ + "language_code": "fr-FR", + "content": "{\"text_message\":{\"text\":\"Message from a template v1.\"}}", + "version": "1", + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ] +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v1/TemplateV1Dto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v1/TemplateV1Dto.json new file mode 100644 index 00000000..b565faf6 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v1/TemplateV1Dto.json @@ -0,0 +1,23 @@ +{ + "id": "id value", + "description": "template description value", + "translations": [ + { + "language_code": "fr-FR", + "content": "{\"text_message\":{\"text\":\"Message from a template v1.\"}}", + "version": "1", + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ] + } + ], + "default_translation": "fr-FR", + "create_time": "2024-08-26T06:00:00Z", + "update_time": "2024-08-26T06:07:44Z", + "channel": "RCS" +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v1/internal/V1ListTemplatesResponseInternalDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v1/internal/V1ListTemplatesResponseInternalDto.json new file mode 100644 index 00000000..05ff26eb --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v1/internal/V1ListTemplatesResponseInternalDto.json @@ -0,0 +1,28 @@ +{ + "templates": [ + { + "id": "id value", + "description": "template description value", + "translations": [ + { + "language_code": "fr-FR", + "content": "{\"text_message\":{\"text\":\"Message from a template v1.\"}}", + "version": "1", + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ] + } + ], + "default_translation": "fr-FR", + "create_time": "2024-08-26T06:00:00Z", + "update_time": "2024-08-26T06:07:44Z", + "channel": "RCS" + } + + ] +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v2/ChannelTemplateOverrideDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/ChannelTemplateOverrideDto.json new file mode 100644 index 00000000..5f431562 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/ChannelTemplateOverrideDto.json @@ -0,0 +1,13 @@ +{ + "template_reference": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + }, + "parameter_mappings": { + "a key": "a value" + } +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v2/TemplateTranslationDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/TemplateTranslationDto.json new file mode 100644 index 00000000..cac806cd --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/TemplateTranslationDto.json @@ -0,0 +1,44 @@ +{ + "language_code": "fr-FR", + "version": "1", + "channel_template_overrides": { + "KAKAOTALK": { + "template_reference": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + }, + "parameter_mappings": { + "a key": "a value" + } + } + }, + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ], + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "template_message": { + "channel_template": { + "KAKAOTALK": { + "language_code": "en-US", + "template_id": "my template ID value", + "version": "a version" + } + }, + "omni_template": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + } + } +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v2/TemplateV2Dto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/TemplateV2Dto.json new file mode 100644 index 00000000..262579f6 --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/TemplateV2Dto.json @@ -0,0 +1,53 @@ +{ + "description": "template description value", + "version": 1, + "default_translation": "fr-FR", + "translations": [ + { + "language_code": "fr-FR", + "version": "1", + "channel_template_overrides": { + "KAKAOTALK": { + "template_reference": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + }, + "parameter_mappings": { + "a key": "a value" + } + } + }, + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ], + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "template_message": { + "channel_template": { + "KAKAOTALK": { + "language_code": "en-US", + "template_id": "my template ID value", + "version": "a version" + } + }, + "omni_template": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + } + } + } + ], + "create_time": "2024-08-26T06:00:00Z", + "update_time": "2024-08-26T06:07:44Z" +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v2/internal/V2ListTemplatesResponseInternalDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/internal/V2ListTemplatesResponseInternalDto.json new file mode 100644 index 00000000..c57f317d --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/internal/V2ListTemplatesResponseInternalDto.json @@ -0,0 +1,57 @@ +{ + "templates": [ + { + "description": "template description value", + "version": 1, + "default_translation": "fr-FR", + "translations": [ + { + "language_code": "fr-FR", + "version": "1", + "channel_template_overrides": { + "KAKAOTALK": { + "template_reference": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + }, + "parameter_mappings": { + "a key": "a value" + } + } + }, + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ], + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "template_message": { + "channel_template": { + "KAKAOTALK": { + "language_code": "en-US", + "template_id": "my template ID value", + "version": "a version" + } + }, + "omni_template": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + } + } + } + ], + "create_time": "2024-08-26T06:00:00Z", + "update_time": "2024-08-26T06:07:44Z" + } + ] +} diff --git a/openapi-contracts/src/test/resources/domains/conversation/templates/v2/internal/V2ListTranslationsResponseInternalDto.json b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/internal/V2ListTranslationsResponseInternalDto.json new file mode 100644 index 00000000..1036ee5f --- /dev/null +++ b/openapi-contracts/src/test/resources/domains/conversation/templates/v2/internal/V2ListTranslationsResponseInternalDto.json @@ -0,0 +1,48 @@ +{ + "translations": [ + { + "language_code": "fr-FR", + "version": "1", + "channel_template_overrides": { + "KAKAOTALK": { + "template_reference": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + }, + "parameter_mappings": { + "a key": "a value" + } + } + }, + "variables": [ + { + "key": "key value", + "preview_value": "preview value" + } + ], + "create_time": "2024-07-07T02:59:59Z", + "update_time": "2024-07-07T06:07:44Z", + "template_message": { + "channel_template": { + "KAKAOTALK": { + "language_code": "en-US", + "template_id": "my template ID value", + "version": "a version" + } + }, + "omni_template": { + "language_code": "another language", + "parameters": { + "name": "Value for the name parameter used in the version 1 and language \"en-US\" of the template" + }, + "template_id": "another template ID", + "version": "another version" + } + } + } + ] +} 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 e0e688f4..165a7239 100644 --- a/sample-app/src/main/java/com/sinch/sample/BaseApplication.java +++ b/sample-app/src/main/java/com/sinch/sample/BaseApplication.java @@ -22,6 +22,7 @@ public abstract class BaseApplication { private static final String CONVERSATION_MESSAGE_ID_KEY = "CONVERSATION_MESSAGE_ID"; private static final String CONVERSATION_EVENT_ID_KEY = "CONVERSATION_EVENT_ID"; private static final String CONVERSATION_WEBHOOK_ID_KEY = "CONVERSATION_WEBHOOK_ID"; + private static final String CONVERSATION_TEMPLATE_ID_KEY = "CONVERSATION_TEMPLATE_ID"; public static final String WEBHOOKS_URL_KEY = "WEBHOOKS_URL"; public static final String WEBHOOKS_VOICE_PATH_KEY = "WEBHOOKS_VOICE_PATH"; @@ -43,6 +44,7 @@ public abstract class BaseApplication { protected String conversationMessageId; protected String conversationEventId; protected String conversationWebhookId; + protected String conversationTemplateId; protected String smsServicePlanId; protected String smsApiToken; protected String applicationKey; @@ -78,6 +80,7 @@ protected BaseApplication() throws IOException { conversationMessageId = getConfigValue(CONVERSATION_MESSAGE_ID_KEY); conversationEventId = getConfigValue(CONVERSATION_EVENT_ID_KEY); conversationWebhookId = getConfigValue(CONVERSATION_WEBHOOK_ID_KEY); + conversationTemplateId = getConfigValue(CONVERSATION_TEMPLATE_ID_KEY); String webhooksUrl = getConfigValue(WEBHOOKS_URL_KEY); if (null != webhooksUrl) { diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Create.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Create.java new file mode 100644 index 00000000..498ce2b2 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Create.java @@ -0,0 +1,41 @@ +package com.sinch.sample.conversation.templates.v1; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import java.io.IOException; +import java.util.Arrays; +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() { + + TemplatesServiceV1 service = client.conversation().templates().v1(); + + TemplateV1 request = + TemplateV1.builder() + .setDefaultTranslation("fr-FR") + .setTranslations( + Arrays.asList(TemplateTranslation.builder().setLanguageCode("fr-FR").build())) + .build(); + + LOGGER.info("Create template: " + request); + TemplateV1 result = service.create(request); + LOGGER.info("Response: " + result); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Delete.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Delete.java new file mode 100644 index 00000000..b112e4d2 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Delete.java @@ -0,0 +1,33 @@ +package com.sinch.sample.conversation.templates.v1; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1; +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() { + + TemplatesServiceV1 service = client.conversation().templates().v1(); + + LOGGER.info("Deleting template: " + conversationTemplateId); + + service.delete(conversationTemplateId); + + LOGGER.info("Done"); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Get.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Get.java new file mode 100644 index 00000000..330647fb --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Get.java @@ -0,0 +1,34 @@ +package com.sinch.sample.conversation.templates.v1; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +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() { + + TemplatesServiceV1 service = client.conversation().templates().v1(); + + LOGGER.info("GET template"); + + TemplateV1 response = service.get(conversationTemplateId); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/List.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/List.java new file mode 100644 index 00000000..bf05a435 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/List.java @@ -0,0 +1,34 @@ +package com.sinch.sample.conversation.templates.v1; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1; +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() { + + TemplatesServiceV1 service = client.conversation().templates().v1(); + + LOGGER.info("List templates V1"); + + var result = service.list(); + + LOGGER.info("Response: "); + result.iterator().forEachRemaining(f -> LOGGER.info(String.format("- %s: %s", f.getId(), f))); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Update.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Update.java new file mode 100644 index 00000000..2874d26a --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v1/Update.java @@ -0,0 +1,42 @@ +package com.sinch.sample.conversation.templates.v1; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v1.TemplatesServiceV1; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v1.TemplateV1; +import java.io.IOException; +import java.util.Arrays; +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() { + + TemplatesServiceV1 service = client.conversation().templates().v1(); + + TemplateV1 request = + TemplateV1.builder() + .setDescription("Updated description from V1 API") + .setDefaultTranslation("fr-FR") + .setTranslations( + Arrays.asList(TemplateTranslation.builder().setLanguageCode("fr-FR").build())) + .build(); + + LOGGER.info("Update template: " + request); + TemplateV1 result = service.update(conversationTemplateId, request); + LOGGER.info("Response: " + result); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Create.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Create.java new file mode 100644 index 00000000..f2ce6ffc --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Create.java @@ -0,0 +1,67 @@ +package com.sinch.sample.conversation.templates.v2; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; +import com.sinch.sdk.domains.conversation.models.v1.ConversationChannel; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import com.sinch.sdk.domains.conversation.templates.models.v2.ChannelTemplateOverride; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +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() { + + TemplatesServiceV2 service = client.conversation().templates().v2(); + + TemplateV2 request = + TemplateV2.builder() + .setDefaultTranslation("fr-FR") + .setTranslations( + Collections.singletonList( + TemplateTranslation.builder() + .setLanguageCode("fr-FR") + .setMessage(TextMessage.builder().setText("my text from template").build()) + .setVariables( + Arrays.asList( + TemplateVariable.builder() + .setKey("they key1") + .setPreviewValue("foo1") + .build(), + TemplateVariable.builder() + .setKey("they key2") + .setPreviewValue("foo2") + .build())) + .setChannelTemplateOverrides( + Collections.singletonMap( + ConversationChannel.WHATSAPP, + ChannelTemplateOverride.builder() + .setParameterMappings( + Collections.singletonMap("they key1", "they key2")) + .build())) + .build())) + .build(); + + LOGGER.info("Create template: " + request); + TemplateV2 result = service.create(request); + LOGGER.info("Response: " + result); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Delete.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Delete.java new file mode 100644 index 00000000..5a4ea091 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Delete.java @@ -0,0 +1,33 @@ +package com.sinch.sample.conversation.templates.v2; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; +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() { + + TemplatesServiceV2 service = client.conversation().templates().v2(); + + LOGGER.info("Deleting template: " + conversationTemplateId); + + service.delete(conversationTemplateId); + + LOGGER.info("Done"); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Get.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Get.java new file mode 100644 index 00000000..0823ed80 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Get.java @@ -0,0 +1,34 @@ +package com.sinch.sample.conversation.templates.v2; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +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() { + + TemplatesServiceV2 service = client.conversation().templates().v2(); + + LOGGER.info("GET template"); + + TemplateV2 response = service.get(conversationTemplateId); + + LOGGER.info("Response: " + response); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/List.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/List.java new file mode 100644 index 00000000..a0abf07b --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/List.java @@ -0,0 +1,34 @@ +package com.sinch.sample.conversation.templates.v2; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; +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() { + + TemplatesServiceV2 service = client.conversation().templates().v2(); + + LOGGER.info("List templates V2"); + + var result = service.list(); + + LOGGER.info("Response: "); + result.iterator().forEachRemaining(f -> LOGGER.info(String.format("- %s: %s", f.getId(), f))); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/ListTranslations.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/ListTranslations.java new file mode 100644 index 00000000..dab935cc --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/ListTranslations.java @@ -0,0 +1,36 @@ +package com.sinch.sample.conversation.templates.v2; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import java.io.IOException; +import java.util.Collection; +import java.util.logging.Logger; + +public class ListTranslations extends BaseApplication { + + private static final Logger LOGGER = Logger.getLogger(ListTranslations.class.getName()); + + public ListTranslations() throws IOException {} + + public static void main(String[] args) { + try { + new ListTranslations().run(); + } catch (Exception e) { + LOGGER.severe(e.getMessage()); + e.printStackTrace(); + } + } + + public void run() { + + TemplatesServiceV2 service = client.conversation().templates().v2(); + + LOGGER.info("List translations for template: " + conversationTemplateId); + + Collection result = service.listTranslations(conversationTemplateId, null); + + LOGGER.info("Response: "); + result.iterator().forEachRemaining(f -> LOGGER.info(String.format("- %s", f))); + } +} diff --git a/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Update.java b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Update.java new file mode 100644 index 00000000..e37b4393 --- /dev/null +++ b/sample-app/src/main/java/com/sinch/sample/conversation/templates/v2/Update.java @@ -0,0 +1,63 @@ +package com.sinch.sample.conversation.templates.v2; + +import com.sinch.sample.BaseApplication; +import com.sinch.sdk.domains.conversation.api.templates.v2.TemplatesServiceV2; +import com.sinch.sdk.domains.conversation.models.v1.messages.types.text.TextMessage; +import com.sinch.sdk.domains.conversation.templates.models.TemplateVariable; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateTranslation; +import com.sinch.sdk.domains.conversation.templates.models.v2.TemplateV2; +import java.io.IOException; +import java.util.Arrays; +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() { + + TemplatesServiceV2 service = client.conversation().templates().v2(); + + TemplateV2 current = service.get(conversationTemplateId); + + TemplateV2 request = + TemplateV2.builder() + .setVersion(current.getVersion()) + .setDescription("Updated description from V2 API") + .setDefaultTranslation("fr-FR") + .setTranslations( + Collections.singletonList( + TemplateTranslation.builder() + .setVersion("1") + .setLanguageCode("fr-FR") + .setMessage(TextMessage.builder().setText("my text from template").build()) + .setVariables( + Arrays.asList( + TemplateVariable.builder() + .setKey("they key1") + .setPreviewValue("foo1") + .build(), + TemplateVariable.builder() + .setKey("they key2") + .setPreviewValue("foo2") + .build())) + .build())) + .build(); + + LOGGER.info("Update template: " + request); + TemplateV2 result = service.update(conversationTemplateId, request); + LOGGER.info("Response: " + result); + } +}