|
| 1 | +/* |
| 2 | + * Conversation API | Sinch |
| 3 | + * |
| 4 | + * OpenAPI document version: 1.0 |
| 5 | + * Contact: support@sinch.com |
| 6 | + * |
| 7 | + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). |
| 8 | + * Do not edit the class manually. |
| 9 | + */ |
| 10 | + |
| 11 | +package com.sinch.sdk.domains.conversation.api.v1.adapters; |
| 12 | + |
| 13 | +import com.fasterxml.jackson.core.type.TypeReference; |
| 14 | +import com.sinch.sdk.core.exceptions.ApiException; |
| 15 | +import com.sinch.sdk.core.exceptions.ApiExceptionBuilder; |
| 16 | +import com.sinch.sdk.core.http.AuthManager; |
| 17 | +import com.sinch.sdk.core.http.HttpClient; |
| 18 | +import com.sinch.sdk.core.http.HttpMapper; |
| 19 | +import com.sinch.sdk.core.http.HttpMethod; |
| 20 | +import com.sinch.sdk.core.http.HttpRequest; |
| 21 | +import com.sinch.sdk.core.http.HttpResponse; |
| 22 | +import com.sinch.sdk.core.http.HttpStatus; |
| 23 | +import com.sinch.sdk.core.http.URLParameter; |
| 24 | +import com.sinch.sdk.core.http.URLParameterUtils; |
| 25 | +import com.sinch.sdk.core.http.URLPathUtils; |
| 26 | +import com.sinch.sdk.core.models.ServerConfiguration; |
| 27 | +import com.sinch.sdk.core.models.pagination.Page; |
| 28 | +import com.sinch.sdk.core.models.pagination.PageNavigator; |
| 29 | +import com.sinch.sdk.core.utils.StringUtil; |
| 30 | +import com.sinch.sdk.domains.conversation.models.v1.consents.ConsentsListType; |
| 31 | +import com.sinch.sdk.domains.conversation.models.v1.consents.internal.ConsentsListResponseInternal; |
| 32 | +import com.sinch.sdk.domains.conversation.models.v1.consents.request.ConsentsListQueryParameters; |
| 33 | +import com.sinch.sdk.domains.conversation.models.v1.consents.response.AuditRecordsResponse; |
| 34 | +import com.sinch.sdk.domains.conversation.models.v1.consents.response.ConsentsListResponse; |
| 35 | +import java.util.ArrayList; |
| 36 | +import java.util.Arrays; |
| 37 | +import java.util.Collection; |
| 38 | +import java.util.HashMap; |
| 39 | +import java.util.List; |
| 40 | +import java.util.Map; |
| 41 | +import java.util.function.Function; |
| 42 | +import java.util.logging.Logger; |
| 43 | + |
| 44 | +public class ConsentsServiceImpl |
| 45 | + implements com.sinch.sdk.domains.conversation.api.v1.ConsentsService { |
| 46 | + |
| 47 | + private static final Logger LOGGER = Logger.getLogger(ConsentsServiceImpl.class.getName()); |
| 48 | + private final HttpClient httpClient; |
| 49 | + private final ServerConfiguration serverConfiguration; |
| 50 | + private final Map<String, AuthManager> authManagersByOasSecuritySchemes; |
| 51 | + private final HttpMapper mapper; |
| 52 | + |
| 53 | + private final String projectId; |
| 54 | + |
| 55 | + public ConsentsServiceImpl( |
| 56 | + HttpClient httpClient, |
| 57 | + ServerConfiguration serverConfiguration, |
| 58 | + Map<String, AuthManager> authManagersByOasSecuritySchemes, |
| 59 | + HttpMapper mapper, |
| 60 | + String projectId) { |
| 61 | + this.httpClient = httpClient; |
| 62 | + this.serverConfiguration = serverConfiguration; |
| 63 | + this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes; |
| 64 | + this.mapper = mapper; |
| 65 | + this.projectId = projectId; |
| 66 | + } |
| 67 | + |
| 68 | + @Override |
| 69 | + public AuditRecordsResponse listAuditRecords(String appId, String identity) throws ApiException { |
| 70 | + |
| 71 | + LOGGER.finest("[listAuditRecords]" + " " + "appId: " + appId + ", " + "identity: " + identity); |
| 72 | + |
| 73 | + HttpRequest httpRequest = listAuditRecordsRequestBuilder(appId, identity); |
| 74 | + HttpResponse response = |
| 75 | + httpClient.invokeAPI( |
| 76 | + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); |
| 77 | + |
| 78 | + if (HttpStatus.isSuccessfulStatus(response.getCode())) { |
| 79 | + return mapper.deserialize(response, new TypeReference<AuditRecordsResponse>() {}); |
| 80 | + } |
| 81 | + // fallback to default errors handling: |
| 82 | + // all error cases definition are not required from specs: will try some "hardcoded" content |
| 83 | + // parsing |
| 84 | + throw ApiExceptionBuilder.build( |
| 85 | + response.getMessage(), |
| 86 | + response.getCode(), |
| 87 | + mapper.deserialize(response, new TypeReference<HashMap<String, ?>>() {})); |
| 88 | + } |
| 89 | + |
| 90 | + private HttpRequest listAuditRecordsRequestBuilder(String appId, String identity) |
| 91 | + throws ApiException { |
| 92 | + // verify the required parameter 'this.projectId' is set |
| 93 | + if (this.projectId == null) { |
| 94 | + throw new ApiException( |
| 95 | + 400, "Missing the required parameter 'this.projectId' when calling listAuditRecords"); |
| 96 | + } |
| 97 | + // verify the required parameter 'appId' is set |
| 98 | + if (appId == null) { |
| 99 | + throw new ApiException( |
| 100 | + 400, "Missing the required parameter 'appId' when calling listAuditRecords"); |
| 101 | + } |
| 102 | + // verify the required parameter 'identity' is set |
| 103 | + if (identity == null) { |
| 104 | + throw new ApiException( |
| 105 | + 400, "Missing the required parameter 'identity' when calling listAuditRecords"); |
| 106 | + } |
| 107 | + |
| 108 | + String localVarPath = |
| 109 | + "/v1/projects/{project_id}/apps/{app_id}/consents/identities/{identity}" |
| 110 | + .replaceAll( |
| 111 | + "\\{" + "project_id" + "\\}", |
| 112 | + URLPathUtils.encodePathSegment(this.projectId.toString())) |
| 113 | + .replaceAll("\\{" + "app_id" + "\\}", URLPathUtils.encodePathSegment(appId.toString())) |
| 114 | + .replaceAll( |
| 115 | + "\\{" + "identity" + "\\}", URLPathUtils.encodePathSegment(identity.toString())); |
| 116 | + |
| 117 | + List<URLParameter> localVarQueryParams = new ArrayList<>(); |
| 118 | + |
| 119 | + Map<String, String> localVarHeaderParams = new HashMap<>(); |
| 120 | + |
| 121 | + final Collection<String> localVarAccepts = Arrays.asList("application/json"); |
| 122 | + |
| 123 | + final Collection<String> localVarContentTypes = Arrays.asList(); |
| 124 | + |
| 125 | + final Collection<String> localVarAuthNames = Arrays.asList("Basic", "oAuth2"); |
| 126 | + final String serializedBody = null; |
| 127 | + |
| 128 | + return new HttpRequest( |
| 129 | + localVarPath, |
| 130 | + HttpMethod.GET, |
| 131 | + localVarQueryParams, |
| 132 | + serializedBody, |
| 133 | + localVarHeaderParams, |
| 134 | + localVarAccepts, |
| 135 | + localVarContentTypes, |
| 136 | + localVarAuthNames); |
| 137 | + } |
| 138 | + |
| 139 | + @Override |
| 140 | + public ConsentsListResponse listIdentities(String appId, ConsentsListType listType) |
| 141 | + throws ApiException { |
| 142 | + return listIdentities(appId, listType, (ConsentsListQueryParameters) null); |
| 143 | + } |
| 144 | + |
| 145 | + @Override |
| 146 | + public ConsentsListResponse listIdentities( |
| 147 | + String appId, ConsentsListType listType, ConsentsListQueryParameters queryParameter) |
| 148 | + throws ApiException { |
| 149 | + |
| 150 | + LOGGER.finest( |
| 151 | + "[listIdentities]" |
| 152 | + + " " |
| 153 | + + "appId: " |
| 154 | + + appId |
| 155 | + + ", " |
| 156 | + + "listType: " |
| 157 | + + listType |
| 158 | + + ", " |
| 159 | + + "queryParameter: " |
| 160 | + + queryParameter); |
| 161 | + |
| 162 | + HttpRequest httpRequest = listIdentitiesRequestBuilder(appId, listType, queryParameter); |
| 163 | + return _fetchListIdentitiesPage( |
| 164 | + (queryParameters) -> listIdentitiesRequestBuilder(appId, listType, queryParameters), |
| 165 | + queryParameter, |
| 166 | + httpRequest); |
| 167 | + } |
| 168 | + |
| 169 | + private ConsentsListResponse _fetchListIdentitiesPage( |
| 170 | + Function<ConsentsListQueryParameters, HttpRequest> requestBuilder, |
| 171 | + ConsentsListQueryParameters queryParameter, |
| 172 | + HttpRequest httpRequest) |
| 173 | + throws ApiException { |
| 174 | + HttpResponse response = |
| 175 | + httpClient.invokeAPI( |
| 176 | + this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest); |
| 177 | + |
| 178 | + if (HttpStatus.isSuccessfulStatus(response.getCode())) { |
| 179 | + |
| 180 | + ConsentsListResponseInternal deserialized = |
| 181 | + mapper.deserialize(response, new TypeReference<ConsentsListResponseInternal>() {}); |
| 182 | + |
| 183 | + String nextToken = deserialized.getNextPageToken(); |
| 184 | + |
| 185 | + ConsentsListQueryParameters nextParameters = |
| 186 | + ConsentsListQueryParameters.builder(queryParameter).setPageToken(nextToken).build(); |
| 187 | + |
| 188 | + final HttpRequest nextHttpRequest = |
| 189 | + !StringUtil.isEmpty(nextToken) ? requestBuilder.apply(nextParameters) : null; |
| 190 | + |
| 191 | + return new ConsentsListResponse( |
| 192 | + () -> _fetchListIdentitiesPage(requestBuilder, nextParameters, nextHttpRequest), |
| 193 | + new Page<>(deserialized.getIdentities(), new PageNavigator<>(nextHttpRequest))); |
| 194 | + } |
| 195 | + // fallback to default errors handling: |
| 196 | + // all error cases definition are not required from specs: will try some "hardcoded" content |
| 197 | + // parsing |
| 198 | + throw ApiExceptionBuilder.build( |
| 199 | + response.getMessage(), |
| 200 | + response.getCode(), |
| 201 | + mapper.deserialize(response, new TypeReference<HashMap<String, ?>>() {})); |
| 202 | + } |
| 203 | + |
| 204 | + private HttpRequest listIdentitiesRequestBuilder( |
| 205 | + String appId, ConsentsListType listType, ConsentsListQueryParameters queryParameter) |
| 206 | + throws ApiException { |
| 207 | + // verify the required parameter 'this.projectId' is set |
| 208 | + if (this.projectId == null) { |
| 209 | + throw new ApiException( |
| 210 | + 400, "Missing the required parameter 'this.projectId' when calling listIdentities"); |
| 211 | + } |
| 212 | + // verify the required parameter 'appId' is set |
| 213 | + if (appId == null) { |
| 214 | + throw new ApiException( |
| 215 | + 400, "Missing the required parameter 'appId' when calling listIdentities"); |
| 216 | + } |
| 217 | + // verify the required parameter 'listType' is set |
| 218 | + if (listType == null) { |
| 219 | + throw new ApiException( |
| 220 | + 400, "Missing the required parameter 'listType' when calling listIdentities"); |
| 221 | + } |
| 222 | + |
| 223 | + String localVarPath = |
| 224 | + "/v1/projects/{project_id}/apps/{app_id}/consents/{list_type}" |
| 225 | + .replaceAll( |
| 226 | + "\\{" + "project_id" + "\\}", |
| 227 | + URLPathUtils.encodePathSegment(this.projectId.toString())) |
| 228 | + .replaceAll("\\{" + "app_id" + "\\}", URLPathUtils.encodePathSegment(appId.toString())) |
| 229 | + .replaceAll( |
| 230 | + "\\{" + "list_type" + "\\}", URLPathUtils.encodePathSegment(listType.toString())); |
| 231 | + |
| 232 | + List<URLParameter> localVarQueryParams = new ArrayList<>(); |
| 233 | + if (null != queryParameter) { |
| 234 | + |
| 235 | + URLParameterUtils.addQueryParam( |
| 236 | + queryParameter.getPageSize(), |
| 237 | + "page_size", |
| 238 | + URLParameter.form, |
| 239 | + null, |
| 240 | + localVarQueryParams, |
| 241 | + true); |
| 242 | + |
| 243 | + URLParameterUtils.addQueryParam( |
| 244 | + queryParameter.getPageToken(), |
| 245 | + "page_token", |
| 246 | + URLParameter.form, |
| 247 | + null, |
| 248 | + localVarQueryParams, |
| 249 | + true); |
| 250 | + } |
| 251 | + |
| 252 | + Map<String, String> localVarHeaderParams = new HashMap<>(); |
| 253 | + |
| 254 | + final Collection<String> localVarAccepts = Arrays.asList("application/json"); |
| 255 | + |
| 256 | + final Collection<String> localVarContentTypes = Arrays.asList(); |
| 257 | + |
| 258 | + final Collection<String> localVarAuthNames = Arrays.asList("Basic", "oAuth2"); |
| 259 | + final String serializedBody = null; |
| 260 | + |
| 261 | + return new HttpRequest( |
| 262 | + localVarPath, |
| 263 | + HttpMethod.GET, |
| 264 | + localVarQueryParams, |
| 265 | + serializedBody, |
| 266 | + localVarHeaderParams, |
| 267 | + localVarAccepts, |
| 268 | + localVarContentTypes, |
| 269 | + localVarAuthNames); |
| 270 | + } |
| 271 | +} |
0 commit comments